Search code examples
bashls

Unable to put colors for LS by LS_OPTIONS


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'  

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