Command Line – How to Easily See the Man Page for Builtin Shell Commands

bashcommand lineshell

If I see a command in a script that I don't know and I type (for example) man pushd or man umask I see the man page for builtin commands. I know that I can do man bash and scroll to find the help for that builtin command, or I can open a browser and go to the online bash man page which is easier to search, but is there an easier way to get the man page for a single builtin command directly on the command line?

Best Answer

Perhaps you like to have some wrapper function which skips directly to the builtin:

man -P "less +/\ \ \ pushd" bash

-P tells man to use less as pager (probably the default on most systems), but pass directly a search to it. You need to add some blanks before the search string to skip hits in text and go to the description of the command.

For convenience make a function out of it and put it into your ~/.bashrc:

function manbash {
   man -P "less +/\ \ \ $1" bash
}

and use it like manbash pushd.


Another possibility is to use the bash builtin help:

$ help pushd
pushd: pushd [-n] [+N | -N | dir]
Add directories to stack.

Adds a directory to the top of the directory stack, or rotates
the stack, making the new top of the stack the current working
directory.  With no arguments, exchanges the top two directories.

Options:
[...]
Related Question