57

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 :-)

3 Answers 3

90

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'
4
  • 3
    No 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
    Oct 28, 2013 at 10:25
  • 25
    On Mac OSX you can use alias ls='ls -G'
    – Gal Bracha
    Aug 6, 2017 at 13:44
  • 4
    also add alias grep='grep --color' to it ;) Jul 7, 2018 at 4:46
  • Put them together like so alias ll='ls -la --color=auto'
    – HackSlash
    Nov 5, 2019 at 17:01
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'
1
  • 1
    Thank you, but I explicitly mentioned in the question: "I don't want an alias". Also, I am satisfied with the current accepted answer, although nothing would prevent you from adding another one, obviously, aliases or not.
    – amn
    Jul 26, 2021 at 18:28
-5

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

2
  • 3
    This is incorrect.
    – Scott
    Nov 24, 2018 at 23:49
  • One can use \ls -alF to test the original ls command and not be confused with an option set elsewhere.
    – Biggybi
    Jan 28, 2020 at 22:11

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.