Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I do use aliases to turn on color for some commands by default. But I'm wondering if there's an easier way at telling my system, color is supported, don't make me use --color for grep, ls, etc.

share|improve this question

1 Answer 1

up vote 8 down vote accepted

FreeBSD has CLICOLOR.

On Linux and any other system with GNU tools, you need to set LS_COLORS, GREP_COLOR, and GREP_OPTIONS='--color=auto', but even then you still need to run ls --color=auto. Run info coreutils 'ls invocation' for more details.

The easiest way I know to avoid typing --color on Linux is to make ls run ls --color=auto using an alias.

This is what I put in my .bashrc (well, really my .env, but it's like .bashrc) to make it happen by default:

# set default flags
if grep --color=auto --quiet "" "$HOME"/.bashrc >/dev/null 2>&1
then
  alias grep='grep --color=auto'
fi
if ls --color=never --directory / >/dev/null 2>&1
then
  # enable colors with GNU ls
  alias ls='ls --color=auto'
else
  alias ls='ls -F'
fi
share|improve this answer
3  
GNU fails in this regard –  xenoterracide Jan 18 '11 at 4:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.