发布于 2020-03-14 02:52:09
快速解决方案:
在Bash命令行中输入以下两个命令:
dircolors -p | sed 's/;42/;01/' > ~/.dircolors
source ~/.bashrc
解释:
有一个用于为ls
设置配置的程序dircolors
。默认的~/.bashrc
脚本使用以下行加载配置:
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
因为在默认情况下,文件~/.dircolors
实际上并不存在,所以脚本使用内置的Bash config (eval "$(dircolors -b)"
)。
要删除o+w
目录的绿色背景(“可由他人写入”权限,由ls
中drwxrwxrwx
符号中的最后一个“w
”标记),您需要基于当前(内置)配置创建此文件。在命令行中键入以下内容:
dircolors -p > ~/.dircolors
dircolor -p
打印当前配置,>
将输出重定向到给定文件。
现在,在编辑器中打开该文件,并找到以下行:
OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
将数字42
(表示绿色背景)更改为01
(无背景)并保存更改。或者,您可以直接从命令行使用sed
程序及其替换功能('s/PATTERN/NEW_STRING/'
语法)来执行此操作:
sed -i 's/;42/;01/' ~/.dircolors
上面两件事可以通过使用管道‘|
’的一条命令来实现:
dircolors -p | sed 's/;42/;01/' > ~/.dircolors
要使更改生效(无需重新启动shell),请键入:
source ~/.bashrc
发布于 2018-03-21 01:34:31
要删除所有背景颜色,请将以下内容放入~/.bashrc:
eval "$(dircolors -p | \
sed 's/ 4[0-9];/ 01;/; s/;4[0-9];/;01;/g; s/;4[0-9] /;01 /' | \
dircolors /dev/stdin)"
发布于 2020-10-29 19:40:14
LS_COLORS
是ls
引用的变量,用于为其输出着色。如果没有设置LS_COLORS
,它将在后台使用dircolors
生成。这也可以使用dircolors
手动设置(参见下面的Vivid )。
如果大多数默认设置都有效,而您只想修复其中的一小部分,那么最简单的方法就是在.bashrc
中设置它们。
LS_COLORS=$LS_COLORS:'tw=00;33:ow=01;33:'; export LS_COLORS
这会将的背景颜色(42
)替换为正常(00
)和粗体(01
带有粘性位的
ow
)的(tw
)
这是最简单的解决方案,因为我们保留了其余的默认值。
另一个答案的技巧
# -b: make dircolors generate for bash
# sed replaces offending background colors
# sed's output is fed as input for another instance of dircolors
# the entire subshell returns LS_COLORS that's `eval`uated
eval $(dircolors -b | sed 's/ 4[0-9];/ 01;/; s/;4[0-9];/;01;/g; s/;4[0-9] /;01 /' | dircolors /dev/stdin)
通过获取所有颜色值并将任何具有背景(4[0-9]
)的内容替换为粗体(01
),即可快速完成此操作。
有更好的替代方案,避免所有的手动操作:
$LS_COLORS
混淆).bashrc
wget https://raw.github.com/trapd00r/LS_COLORS/master/LS_COLORS -O $HOME/.config/LS_COLORS
echo 'eval $(dircolors -b "$HOME/.config/dircolors")' >> $HOME/.bashrc
使用基于theme生成必要颜色代码的vivid
命令在.bashrc
中使用
export LS_COLORS="$(vivid generate molokai)"
这两种工具配色方案都没有任何类型的目录的背景色。
https://stackoverflow.com/questions/40574819
复制相似问题