问题
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 eval
uates 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 eval
uates 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