Can I have color ls output automatically if my TERM is "xterm-256color"?

Solution 1:

If you are using bash, you could add export CLICOLOR="YES" to your ~/.bashrc.

Solution 2:

Just for the sake of anyone who might come along and wonder how to restrict this to only when the TERM is a certain value, you could put something like this in your shell's "rc" file (.zshrc or .bashrc etc):

case "$TERM" in 

    xterm-256color)
        export CLICOLOR="YES"
    ;;

    *color|xterm*)
        export CLICOLOR="YES"
    ;;

    vt100)
        export CLICOLOR="NO"
    ;;

esac

Note that the 2nd example is just there to show why you might want to use 'case' instead of 'if/then': the ability to use wildcard matching and use multiple entries separated by |