Today, we are going to learn some simple tips and tricks to read man pages effectively in Linux. As you might already know, a man page is divided into several parts, each with a distinct heading. You might have to scroll down for quite a long time when you're looking for a particular information on the specific flag/option. It is really inefficient and time consuming task. This is why it is important to learn to use Linux man pages efficiently to find out what exactly you want to know.
Table of Contents
Learn to Use Linux Man Pages Efficiently
As we all know, we can open the man page of a command, for example mkdir
, using command:
$ man mkdir
This is how mkdir
command's man page looks like.
The Structure of a Man Page
As you see in the above screen, a typical man page consists of several sections, organized with headings for each section, such as NAME, SYNOPSIS, CONFIGURATION, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUE, ERRORS, ENVIRONMENT, FILES, VERSIONS, CONFORMING TO, NOTES, BUGS, EXAMPLE, AUTHORS, and SEE ALSO. Some man pages have all of these sections and some doesn't have.
The format in general for pages in man is;
- Letters in bold are to be written exactly as they are.
- Words in between [] are options, that is, they can be sent as arguments to the command.
- Letters in italic are to be substituted with your arguments.
Navigate Linux Man Pages
Press "UP arrow" key to move forward one line and press "DOWN arrow" key to move backward one line. Alternatively, you can press "j
" or "e
" to move forward one line and press "k
" or "y
" to move backward one line.
Press "Right arrow" key to move right one half screen width and press "Left arrow" key to move left one half screen width.
Press "SPACEBAR" to move forward one window. You can also press "f
" to move forward one window and press "b
" to move backward one window.
Press "d
" to move forward one-half window and press "u
" to move backward one-half window.
Please note that default "window" is your screen height. And the default "half-window" is half of the screen height.
To go to the end of the man page, press End key and to go to the first page of a man page, press Home key.
Press "h
" key in the currently opened man page to know all useful keyboard shortcuts and general usage information.
Press q
to exit the man page. Alternatively, use :q
, Q
(shift+q
), :Q
, ZZ
to exit man page.
Here is the list of useful keyboard navigation controls to browse man pages in Linux and Unix.
Keybindings | Navigation |
UP Arrow | Move forward one line |
Down Arrow | Move backward one line |
j or e | Move forward one line |
k or y | Move backward one line |
Right Arrow | Move right one half screen width |
left Arrow | Move left one half screen width |
Spacebar or f | Move forward one window |
b | Move backward one window |
d | Move forward one-half window |
u | Move backward one-half window |
Home key | Go to the first page of a man page |
End key | Go to the end of the man page |
h | Display help section of currently opened man page |
q, :q, Q (shift+q), :Q, ZZ | Exit man page |
Show Manual Page Names Matching to a Keyword
We can search for man pages containing a specific keyword using -k
flag.
For example the following command displays the manual page names for the keyword "mkdir
" as regular expression.
$ man -k mkdir
Sample output:
gvfs-mkdir (1) - (unknown subject) mkdir (1) - make directories mkdir (1posix) - make directories mkdir (2) - create a directory mkdirat (2) - create a directory
As you see in the above output, It displays any matches that contains the string "mkdir
". To strictly limit the search within the matched string, use:
$ man -k '^mkdir'
Sample output:
mkdir (1) - make directories mkdir (1posix) - make directories mkdir (2) - create a directory mkdirat (2) - create a directory
It is equivalent to the following command:
$ apropos mkdir
You can also use -f
flag to search man pages matching to the keyword "mkdir
" along with the description (if there are available):
$ man -f mkdir
Sample output:
mkdir (1) - make directories mkdir (2) - create a directory mkdir (1posix) - make directories
It is equivalent to the following command:
$ whatis mkdir
Recall a Forgotten Command
We already have published a guide that described how to easily recall forgotten Linux commands. That guide is quite useful if you don't know which command to use to perform a specific task.
We can also do it using man pages with the help of -k
flag. Let us say, you want to create a directory, but you couldn't remember what command we use to create a directory.
To do so, use grep command with man like below:
$ man -k directory | grep create
Sample output would be:
mkdir (2) - create a directory mkdirat (2) - create a directory mkdtemp (3) - create a unique temporary directory mkfontdir (1) - create an index of X font files in a directory mklost+found (8) - create a lost+found directory on a mounted Linux second extended file system mktemp (1) - create a temporary file or directory pam_mkhomedir (8) - PAM module to create users home directory update-info-dir (8) - update or create index file from all installed info files in directory
Just read the description of the each command and pick the suitable command. Ahh, you now remember. mkdir
is the one that you're looking for, isn't it? It's that simple.
Search within Man Pages
Once you're in a man page, you may want to look for specific string. To do so, just type /
(forward slash) followed by the search string like below
/<search_string> or <pattern>
Let us say, you're in the man page of mount
command:
$ man mount
and you want to look for information on the bind
option. To do so, type the following inside the man page:
/bind
Any matches to the search string in the current man page will get highlighted.
Press "n
" and "SHIFT+n
" to browse through the next and previous matches.
The /pattern(or string)
will search forward for (N-th) matching line.
You can also do the backward searching using ?pattern
. This can be helpful if you are in the middle or at the end of the man page.
?bind
To display only matching lines, type:
&bind
In this search method, you don't have to use "n" or "shift+n" to scroll through next and previous matches. &pattern
will only display the matching lines that contains the search term, everything else will be omitted.
Search Matches without Opening Man Page
It is also possible to search for details of a specific option without opening the man pages.
For instance, let us say you're looking for information on the -m
option of mkdir
command. To find it out, run:
$ man mkdir | grep -e '-m'
Or,
$ man mkdir | grep -- '-m'
This command will display the first occurrence of -m
flag in the man page of mkdir
command. As we see in the above command -m
represents MODE (chmod
).
If you want to see the complete man page of mkdir
command but skip directly to the first occurrence of -m
, use the following command:
$ man mkdir | less +/-m
Here is another example:
$ man mount | less +/--bind
Press "n
" and "SHIFT+n
" to browse through the next and previous matches.
Suggested Read:
View a Specific Section in Man Pages
Like I already said, a man page consists of several different sections. Each man page has its command name followed by the section number in parenthesis. You can easily and quickly see a specific section in man pages using section number. Refer the following guide for more details.
Export Entire Man Page to Text File
We can export the entire man page of a specific command to a text file. To do so, just run the following command:
$ man mount > mount.txt
This command will export the man page of the mount command to "mount.txt file
" and save it in the current directory.
It is also possible to obtain a simpler version of a man page, without backspaces and underscores, using the following command.
$ man mount | col -b > mount.txt
View Location of a Man Page
Ever wondered where are the man pages stored in your Linux system? The following command will display the location of a man page rather than the man page itself:
$ man -w uname
Sample output:
/usr/share/man/man1/uname.1.gz
Alternatively, use the "path
" flag to display the man page location.
$ man --path uname /usr/share/man/man1/uname.1.gz
You can also display the path location of uname
man page from section 2 like below.
$ man --path uname.2 /usr/share/man/man2/uname.2.gz
Find the Longest Man Page
As we've seen in the previous section, all commands' man pages are stored in /usr/share/man/
directory in Linux. Curious to know which command has the biggest manual page on your Linux system? Refer this guide.
Getting help
To know more details about man pages, run:
$ man man
$ man -k man
$ info man
This command will display the man page about the man pages.
Conclusion
These tricks are just basics but enough to navigate Linux man pages efficiently. These tricks will save you a lot of time and avoid unlimited scrolling through lengthy man pages.
3 comments
shortcut to ‘man -k grep’-combo is the ‘apropos’ command.
Remember that the output of the man command will be influenced by whatever the environmental variables MANPAGER or PAGER are set to, and the width of the output can be customized with MANWIDTH.
On an X11 desktop, the “xless” makes a good pager if properly configured (background color etc).
Hi,
Very Useful Article
Thanks a lot…