11

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.

9

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
1
  • 3
    GNU fails in this regard Jan 18 '11 at 4:34
0

There isn't a standard for forcing colours.

CLICOLOR is increasingly common, and there's an attempt to standardise it too.

You can alias commands to provide the --color=auto (or equivalent) flag by default in your .bashrc, but you'll need to find the relevant flag for each command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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