6

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.

Dason
  • 273

2 Answers2

11

ls doesn't control scrolling through the terminal output, your terminal does; by the time you're doing that ls has already terminated. Your terminal probably supports a hotkey to handle it; Page Up and Shift+Page Up are common choices

Michael Mrozek
  • 93,103
  • 40
  • 240
  • 233
  • Good answer and Shift + Page Up works but I was hoping to keep the keybindings of something like less so I don't need to go over to pageup/pagedown to scroll. – Dason Feb 09 '11 at 22:57
  • 1
    Might I point out that switching over to the mouse is generally even more movement than going to pageup. At any rate it sure does sound like you could improve the terminal client setup you're on. – Steven Lu Aug 13 '13 at 15:00
11

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.