Changing color of my directories listed by my directory

走远了吗. 提交于 2019-12-25 02:36:21

问题


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

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

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

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

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?


回答1:


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

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


来源:https://stackoverflow.com/questions/21030102/changing-color-of-my-directories-listed-by-my-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!