Linux console output – pause after each screen

consolelinuxlinux terminalterminal

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.

Best Answer

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.