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.

2 Answers 2

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.

3
  • Precisely what I was looking for. Thank you.
    – Dason
    Feb 9, 2011 at 22:56
  • Interesting. I have never seen --color=yes; I always used color=always or color=auto. May 30, 2013 at 13:29
  • hmm how do I then scroll through the list? Sorry I'm a n00b to linux
    – J86
    Feb 21, 2018 at 16:06
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

2
  • 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 9, 2011 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, 2013 at 15:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .