73

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

107

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'
5
  • 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 :-) Commented Oct 28, 2013 at 10:25
  • 31
    On Mac OSX you can use alias ls='ls -G'
    – Gal Bracha
    Commented Aug 6, 2017 at 13:44
  • 4
    also add alias grep='grep --color' to it ;) Commented Jul 7, 2018 at 4:46
  • Put them together like so alias ll='ls -la --color=auto'
    – HackSlash
    Commented Nov 5, 2019 at 17:01
  • A reason not to use aliases is that they are not always available. When shelling out from ruby or python, or when running a remote command over ssh, your aliases will be ignored and only the bare /bin/ls will run.
    – Daniel
    Commented Sep 7, 2023 at 20:40
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. Commented 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. Commented Nov 24, 2018 at 23:49
  • 1
    One can use \ls -alF to test the original ls command and not be confused with an option set elsewhere.
    – Biggybi
    Commented Jan 28, 2020 at 22:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .