Ubuntu bash/ohmyzsh绿色背景问题

Ubuntu下 bash / zsh / ohmyzsh绿色背景问题及解决方案

问题

ubuntu下安装了zshohmyzsh,或使用默认shell等,使用ls命令,部分目录的背景绿色,看起来十分别扭,如下图:
在这里插入图片描述

解决方案如下:

细节不看版

  1. 如果使用的是zshohmyzsh,首先执行以下命令,如果使用的是默认shell,跳过这一步
vim ~/.zshrc 
# 按i开始编辑
# 把以下命令加入到文件末尾
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi
# 按ESC :wq 保存退出
source ~/.zshrc
  1. 执行
cd ~
dircolors -p > .dircolors
vim .dircolors  

找到 OTHER_WRITABLE 34;42, (大约在60~70行),将34;42修改为01;34
如果使用默认的shell,执行

source ~/.bashrc

如果使用的是zshohmyzsh,执行

source ~/.zshrc
  1. 再次使用ls命令验证一下,绿色背景消失了:
    在这里插入图片描述

细节版

问题原因

文件夹的读写执行权限过高,ls命令会为其标注绿色背景

颜色及背景配置

.dircolors 指明文件/文件夹的颜色,位于/home/username/下,对于其中的变量,以OTHER_WRITABLE 34;42为例,第一个参数代表文件(夹)类型, 第一个数字指定其前景颜色,第二个数字指定其背景颜色。我们可以指定自己喜欢的前背景颜色,我更喜欢与普通的文件夹保持风格一致,所以使用了01;34.

bash / zsh / ohmysh

~/.bashrc中,指定了使用.dircolors的配置来显示颜色,即上述添加的部分

# 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)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

所以对于bash,修改.dircolors即可。
对于zsh / ohmyzsh , 先要指定其使用.dircolors, 所以要在 ~/.zshrc中添加上述语句。最后记得让配置生效

source ~/.zshrc
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值