在默认终端中永久禁用颜色

Kdr*_*umz 12 colors

我不知道如何禁用终端中的颜色(只是默认的,它被称为 gnu?)。找了一个小时并运行了一些我在其他地方看到的代码。还尝试了emacs ~/.bashrc并添加了一条应该禁用颜色的行,它工作了一次,然后我关闭了终端,再次ls,颜色又回来了。任何帮助都很棒!

Anw*_*war 11

在你的.bashrc文件中,你会发现行

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
Run Code Online (Sandbox Code Playgroud)

在行#前放置一个注释符号force_color_prompt=yes并重新启动终端。更改后,该行应为

#force_color_prompt=yes
Run Code Online (Sandbox Code Playgroud)

编辑:这将从终端变成颜色。但是,如果某些程序内置了颜色支持,并且您也想关闭它们,请按照@Zanna 的回答进行操作。基本上你需要注释掉诸如alias ls='ls --color=auto'等的行。

  • @KyleDrummond 我很困惑你为什么接受安华的回答。尽管 Anwar 的答案是正确的,但您从来没有取消对 `force_color_prompt` 的注释,所以这个解决方案虽然正确,但并不能解决您的问题。Zanna 提供了真正有效的解决方案。 (7认同)
  • 打开的时候**force_color_prompt=yes**前面已经有**#**了,之前没碰过。奇怪,还有什么我可以尝试的吗? (2认同)

Zan*_*nna 10

如果您设置了彩色提示,请参阅@Anwar 的回答

命令输出的颜色ls由别名构成。

要禁用此功能,请在您的 ~/.bashrc

alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias ls='ls --color=auto'
Run Code Online (Sandbox Code Playgroud)

完成后,source ~/.bashrc立即生效或关闭终端并打开一个新终端

  • @KyleDrummond 这很奇怪,但我看到你通过打开一个新终端让它工作。顺便说一句,Anwar 的回答只是告诉您如何阻止提示 (`user@mycomputer:~$`) 被着色,这个回答告诉您如何停止诸如 `ls` 之类的命令的输出中的颜色,我认为这是您想要的?您能否在接受其他答案时澄清? (2认同)