78

I don't want an alias (alias ls='ls --color'), and I had previously set this up on Mac OSX using CLICOLOR environment variable which magically brought colors to ls. Now I am on Linux (Arch x86-64) with xterm and a really basic setup, and I can't make ls output color (using ls verbatim). I do get color when using --color switch.

Is there no way to achieve this without an alias? POSIX compliance would be nice :-)

11 years later:

Ok, I obviously can no longer remember why I absolutely did not want an alias, but speculating in hindsight, it may have had something to do with running scripts that defer to ls and wanting colour because the script were to be run interactively, with a terminal [emulator]. Since the shell that runs a script does not read the kind of initialization files where aliases are normally set up (unless you source the script, which isn't the same thing), it will invoke the ls program itself, not an alias, and that beget this question, I suppose. Mind you, I am merely offering my speculation for some context.

3 Answers3

116

There is no way: the ls man page will show you that the default setting (for --color) is 'none' - ie. never use colour.

Any reason you don't want to use aliases? I'm a recovering Red Hat user, so every time I install a new distribution I set three ls aliases like so:

## Colorize the ls output ##
alias ls='ls --color=auto'

## Use a long listing format ##
alias ll='ls -la'

## Show hidden files ##
alias l.='ls -d .* --color=auto'
pdah
  • 1,394
0

You can use the alias method so that every time you open the terminal and use ls (verbatim just ls , not ls --color), results will be coloured. You can add the alias to your .bashrc, for example, as the following command line:

alias ls='ls --color=auto'
-6

if using the -F option --color is unnecessary, for instance alias ll='ls -alF' shows colors

Mark
  • 1