Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 10 down vote accepted

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.

share|improve this answer
    
Precisely what I was looking for. Thank you. –  Dason Feb 9 '11 at 22:56
    
Interesting. I have never seen --color=yes; I always used color=always or color=auto. –  Alberte Romero May 30 '13 at 13:29

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

share|improve this answer
    
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 '11 at 22:57
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.