2

From man ls:

With --color=auto,
       ls emits color codes only when standard output is connected to a terminal.

Just being curious. What would hurt if I emits color when standard output is not connected to a terminal?

Becasue emitting color needs extra computation so if standard ouput isn't connected to a terminal, we don't need that and can save some computations?

3
  • your title Q and body Q seem to differ — but as for the body, coloration is via escape sequences and the program on the other end of a pipe might not deal with them as you expect
    – Fox
    Dec 19, 2020 at 2:59
  • @Fox Yes, I get it now. :)
    – Rick
    Dec 19, 2020 at 3:10
  • There is no defaults. In many shell setups, your ~/.bashrc is defining ls as some alias. Try using /bin/ls Dec 19, 2020 at 6:57

1 Answer 1

5

I get it now.

What color codes means is that ls --color=always would output some extra text describing colors and normally the terminal would eat up these texts.

However, when ls --color=always > test.txt, the addtional text describing colors would be preserved and saved.

Try ls --color=always > file1.txt and ls --color=auto > file2.txt and open both files e.g. with nano and you can see the differences.

You must log in to answer this question.

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