5

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?

2 Answers 2

9

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.

7
  • 1
    Potentially confusing as hell, but undeniably a neat trick.
    – womble
    Jun 25, 2009 at 23:30
  • Dennis, That rocks! ZSH equivalent is: bindkey -s "\C-j" "|less\C-m" Jun 26, 2009 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, 2013 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). Apr 26, 2013 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). Apr 26, 2013 at 15:40
1

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

You must log in to answer this question.

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