更改目录列出的目录颜色 [英] Changing color of my directories listed by my directory

查看:162
本文介绍了更改目录列出的目录颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过编辑.dircolors文件来更改ls命令的目录列表的颜色/属性,但这不起作用.

I tried changing the color/attributes of directory listings of ls command by editing .dircolors file but it doesn't work.

在此之前值得一提的是,我在bash.bashrc文件中添加了以下更改.

Before that it is worth mentioning that i have added the below changes in the bash.bashrc file.

# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
[ -e "$HOME/.dircolors" ] && DIR_COLORS="$HOME/.dircolors"
[ -e "$DIR_COLORS" ] || DIR_COLORS=""
eval "`dircolors -b $DIR_COLORS`"
alias ls='ls --color=auto'
#alias dir='ls --color=auto --format=vertical'
#alias vdir='ls --color=auto --format=long'
fi

此外,还在bashrc中添加了以下代码,用于指定dircolors文件路径.

Also , added the below code in bashrc for specifying the dircolors file path.

d=.dircolors
test -r $d && eval "$(dircolors $d)"

在开始使用ubuntu时,我对这些事情只有一个模糊的想法. 那么有人可以帮我找出为什么不能更改ls命令颜色的原因吗?

I just got a vague idea about these things as am just beginning to work with ubuntu. So can someone please help me find out the reason about why am not able to change colors of ls command?

推荐答案

您似乎多次(不必要)进行了一些测试和评估.这是Ubuntu框架.bashrc文件中存在的标准习惯用法:

You seem to be doing some of the tests and evals multiple (unnecessary) times. Here's the standard idiom present in Ubuntu skeleton .bashrc files:

if [ -x /usr/bin/dircolors ]; then
    [ -r ~/.dircolors ] && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
fi

这测试dircolors程序在系统上是否可用(并且可以由您执行).如果是这样,则它检查.dircolors文件在您的主目录中是否存在(并且可读).如果是这样,它将使用您的.dircolors文件作为输入执行dircolors命令,并使用eval u输出(基本上只是设置LS_COLORS环境变量).如果您没有.dircolors文件,那么它将使用默认颜色执行dircolors(然后再次eval对该输出进行求值).

This tests whether the dircolors program is available (and executable by you) on your system. If so, then it checks whether the .dircolors file exists (and is readable) in your home directory. If so, it executes the dircolors command using your .dircolors file as input and evaluates the output (which basically just sets the LS_COLORS environment variable). If you don't have a .dircolors file, then it executes dircolors with the default colors (and once again evaluates that output).

完成后,您可以检查它产生的设置:

When it's done you can check the settings it produced:

echo $LS_COLORS

您可以通过运行以下内容来进一步了解所有这些颜色的含义:

You can read a bit more about what all these colors mean by running:

dircolors --print-database

这篇关于更改目录列出的目录颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆