Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'd like to configure bash to page the output of all commands. Essentially, I want bash to behave as if every command I enter ended with '| less'. Is this possible?

share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

You could do this:

$ bind '"\C-j": "|less\C-m"'

Or put this in your ~/.inputrc:

"\C-j": "|less\C-m"

Then when you want to do ls -l|less you'd type ls -l and press control-J instead of <enter>.

I would not recommend swapping the j and m in the bind command (or in the .inputrc file). Every time you'd press <enter> you'd get |less added which could be pretty annoying.

share|improve this answer
1  
Potentially confusing as hell, but undeniably a neat trick. –  womble Jun 25 '09 at 23:30
    
Dennis, That rocks! ZSH equivalent is: bindkey -s "\C-j" "|less\C-m" –  Kyle Brandt Jun 26 '09 at 11:41
    
@dennis-williamson, did you know how can I fix this binding, for queued commands? For example enter in bash "sleep 10", and don't wait when "sleep 10" finished, "ls" + enter, and for "ls" command "|less" will be added. –  azat Apr 25 '13 at 20:36
    
@azat: It works for me. I tried by using the bind command shown above (or the .inputrc binding), typing sleep 10 and immediately typing ls -l (don't press enter) and then press Control-J (the enter is built in to the binding as \C-m). –  Dennis Williamson Apr 26 '13 at 14:02
1  
@azat: Oh! To fix that bind the sequence to something other than Control-J and use that keystroke to add the less and carriage return to commands that you want. The reason for this problem is that Control-J is normally bound to accept-line as is Control-M (enter). –  Dennis Williamson Apr 26 '13 at 15:40
show 2 more comments

I'm not sure if this is possible, but you can definitely make it easier on yourself by doing something like this in your .bashrc:

alias p='less'

ll |p then becomes a paged listing.

EDIT: As a note though this still wont work for something that is going to STDERR. You would need to something like: errorcommand 2>&1 |p

share|improve this answer
add comment

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.