Linux console output - pause after each screen
15,711
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.
Author by
Meir Rotfleisch
Updated on September 17, 2022Comments
-
Meir Rotfleisch over 1 year
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.
-
OWSam almost 14 yearsIf you have
--color=auto
thenls
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. -
Dennis Williamson almost 14 yearsFrom
ls --help
: "Using the --color option without the optional WHEN argument is equivalent to using --color=always." -
Meir Rotfleisch almost 14 yearsI have to make sure coloring is enabled AND that "less" interprets the color escape chars. Thanks, this is the result I was looking for.