Scrolling through ls output without a mouse

lsterminal

In some directories there are quite a few files. When I use ls the output is more than my terminal can handle. Typically I just use one of the following:

ls | less
ls | more

depending on my mood. However, I lose the color coding and I only get a single file/directory per line. Is there a way to emulate scrolling through my terminal with my mouse after I use ls without actually having to scroll? I checked the man page for ls and I didn't see anything that would allow for this but I may have missed something.

Best Answer

You want ls -C --color=yes | less -R. -C forces ls into multi-column mode even when it's being piped, --color=yes forces ls to always output in color, even when being piped, and the -R argument to less forces it to interpret raw terminal escape codes.

In the general case, you might also consider GNU Screen if your terminal isn't configured to support hotkeys like Michael Mrozek mentioned.

Related Question