How to make `ls` color its output by default, without setting up an alias?

48

9

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? POSIX compliance would be nice :-)

amn

Posted 2013-10-25T12:46:58.087

Reputation: 1 622

Answers

71

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

Posted 2013-10-25T12:46:58.087

Reputation: 914

17On Mac OSX you can use alias ls='ls -G' – Gal Bracha – 2017-08-06T13:44:21.583

2also add alias grep='grep --color' to it ;) – AmirHossein – 2018-07-07T04:46:04.593

Put them together like so alias ll='ls -la --color=auto' – HackSlash – 2019-11-05T17:01:34.993

2No reason I cannot - I was on Mac OSX the other day, and it supported the CLICOLOR which I thought was kind of standard (you always tend to think that these things are standard). And I also always thought of aliases as more of an retrofit solution. But they'll do just fine :-) – amn – 2013-10-28T10:25:04.240

-3

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

Mark

Posted 2013-10-25T12:46:58.087

Reputation: 5

3This is incorrect. – Scott – 2018-11-24T23:49:39.190

One can use \ls -alF to test the original ls command and not be confused with an option set elsewhere. – Biggybi – 2020-01-28T22:11:08.137