Probably been answered somewhere, but its difficult to frame the search phrase.
I am running a bash terminal window and some commands are too big to fit on the page (e.g. ps -A
)
I vaguely recall a command line parameter / method that shows the command output page by page so I can scroll through the output, but I can't recall what it is…. any pointers?
Best Answer
For commands I use often, I generally set up a
function
in my .bashrc to make them paginate if longer than a screen.Like your example: (ps -A)
This replaces
ps
with a function, namedps
, which calls the originalps
command with whatever arguments given on the command line, then pipes the output (stdout and stderr, using the|&
pipe) intoless -F
, which pauses if there's more than a screen-full, but exits immediately if it's less than a screen-full.VERY handy, doesn't interfere with anything I've worked with so far, and is just cool!
You can even add oft-used options into the command/functions too:
This makes
nm
always demangle C++ symbols. AND paginates the output. Yay!I'm running Debian, so I use the
apt-cache
command quite often, search and show mostly. This function causes those particular options to paginate, search output is sorted, and everything paginates:If the command is 'search', sort the output, then paginate with
less -F
, but if command is anything else, just paginate, without sorting.Occasionally I forget I've got the functions, and I'll do something like:
The function doesn't interfere, everything works as expected, no harm either way.
Another little tweak, I use the same
.bashrc
on all my systems, so sometimes a utility might not be installed, so there's no need for the function. I make them conditional like this:This just uses the
which
command to determine if a program is available, if it isn't, it quietly fails and skips installing the function. Taa Daa!