I often pipe commands to less in order to read through the output (e.g. compiler errors).MyCommand | lessThis is great because it makes trawling through large amounts of output easy, but when I exit less the output is gone. How can I make the output still visible after quitting less?This question differs from Is there a way to redirect a program's output and still have it go to stdout? because that question relates to output to a text file via tee, which, as far as I know, doesn't provide a facility to split output between less and stdout.
How do I prevent less from clearing the screen on exit?
bash;less
Using less -X:Disables sending the termcap initialization and deinitialization strings to the terminal.That will leave any text on-screen behind before and after paging. So:command | less -Xwill have the effect you want. Note that this output will still be wrong (duplicated lines) if you ever scrolled up - that's unavoidable without without writing to a file.You can also set the environment variable LESS to a value that contains X to do this by default for every invocation of less.If you want to write to a file without resorting to tee, you can use the less -o filename or --log-file=filename options.