Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

when I list directories with a lot of files with ls -la or tree -L 3 I get many screens of output. To read one screen after another I add | more or | less, but the problem with this is that the coloring is lost.

Is there a way to make the console pause after each screen full of information but keep the coloring?

Thanks.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

When you type: ls, the command knows that the output is being displayed to your tty, and enabled color. When the command detects output being sent elsewhere, its going to strip the color escape codes.

So to enable color when piping output, use either ls --color, or ls -G on mac.

Then for less, you will need to append the -R flag, which maintains ANSI color escape chars.

ls -la --color | less -R

That should yield the results you are looking for.

share|improve this answer
2  
If you have --color=auto then ls will display color if there is no pipe. If there is a pipe, it won't display the color. Having --color=always gives pipes color. –  Nitrodist Aug 2 '10 at 19:33
1  
From ls --help: "Using the --color option without the optional WHEN argument is equivalent to using --color=always." –  Dennis Williamson Aug 2 '10 at 19:44
    
I have to make sure coloring is enabled AND that "less" interprets the color escape chars. Thanks, this is the result I was looking for. –  vobject Aug 2 '10 at 19:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.