快速解决方案:
在 Bash 命令行中输入这两个命令:
dircolors -p | sed 's/;42/;01/' > ~/.dircolors
source ~/.bashrc
说明:
有一个程序dircolors 旨在为ls 设置配置。
默认的~/.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 配置 (eval "$(dircolors -b)")。
要删除o+w(drwxrwxrwx 中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