Linux console output - pause after each screen

5

1

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.

vobject

Posted 2010-08-02T19:21:03.763

Reputation: 195

Answers

6

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.

David Houde

Posted 2010-08-02T19:21:03.763

Reputation: 424

2If 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 – 2010-08-02T19:33:04.160

1From ls --help: "Using the --color option without the optional WHEN argument is equivalent to using --color=always." – Paused until further notice. – 2010-08-02T19:44:30.287

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 – 2010-08-02T19:45:44.530