Question

I find out that you can have the following for Grep in .bashrc

 # puts colors for all grep commands
 export GREP_OPTIONS='--color=auto'

I did not manage to get the similar command for LS_OPTIONS to work.

Is there any other way than the following to give colors for your ls -command?

alias ls='ls -Gh'  
Was it helpful?

Solution

Here's a complete solution:

# BSD ls
export LSCOLOR='exfxcxdxbxegedabagacad'
# GNU ls and others (for example, tree)
export LS_COLORS='di=34;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=34;46:cd=34;43:su=0;41:sg=0;46:tw=0;42:ow=0;43:'

if [ "$(uname -s)" = 'Linux' ]; then
  # GNU ls
  alias ls='ls --color=auto'
else
  # Assume BSD ls
  alias ls='ls -G'
fi

OTHER TIPS

For ls with colors to work you must do the following:

alias ls='ls -G'
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
export TERM=xterm-color 

As others have said, aliasing ls with explicit options accomplishes what you want. If, however, you are especially keen on actually using the environment variable LS_OPTIONS, well, you still need an alias: alias ls='ls $LS_OPTIONS '

You would set LS_OPTIONS to any string of valid command-line options for ls. Run ls --help or man ls on the command-line to see what options are available. On my Linux system (openSuSE 42.2), with GNU ls v8.25, you would get coloured output by adding the option --color=auto.

So you would put the following in your ~/.profile or ~/.bashrc file:

export LS_OPTIONS="--color=auto"
alias ls="ls $LS_OPTIONS "

To add additional options to the environment variable or the alias, just add them (separated by spaces) inside the double-quotes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top