How to Use Linux’s man Command: Hidden Secrets and Basics

A terminal prompt on a Linux laptop.Fatmawati Achmad Zaenuri / Shutterstock

Everything you need to know about Linux can be found in its manual pages. For example, you can search for an order to accomplish a task, even if you don’t know what it’s called. But how do you find the manual pages? Here are some tips.

Integrated Linux Manual

There is an old Linux joke (from the Unix golden era) that the only command you should know is the man the system user manual access point. There is a bit of truth in it, but even humans can be confusing at first. Or, more specifically, finding the information you need can be confusing.

Have you ever known what you wanted to do, but you didn’t know the name of the command that would accomplish the task? We have probably all been there. It’s like trying to find a word in the dictionary when you don’t know it.

So how can you find what you are looking for? Well, there are ways to get around this dilemma with humans.

Another first-year problem is numbers. What are they and what do they mean? You will see things like man (2) or man (5) cited in the documentation and on the Internet. You will also see references to commands followed by numbers, such as mount (2) and mount (8). Surely there can’t be more than one mount command, right? As we will see, the numbers are large and relatively simple.

Speaking of simple, research within humans is fairly easy once you know how to do it. In fact, there are interesting ways to search and navigate humans. Let’s turn it on and take a look!

RELATED: 37 important Linux commands you should know

How to open the manual

To use man, you type man on the command line, followed by a space and a Linux command. man opens the Linux manual on the “manual page” that describes this command – if it can find it, of course.

Let’s type the following and see what the man says about the man:

man man

The man manual page opens.

As you can see, this is the man page (1).

Follow these tips to navigate the page:

To browse the manual page one line at a time: Use the scroll wheel on your mouse or the up and down arrows and the Enter keys.
To navigate the manual page one screen at a time: Press the space bar and the PgDn and PgUp keys.
To go directly to the top or bottom of the manual page: Press the Home and End keys.

If you press H, you go to the help section and see a table of key combinations you can use. Those listed above will probably feel more natural for most people.

To leave the man, just press Q.

The anatomy of a man Page

At the top of the page, you see the “Name” and “Synopsis” sections. The layout of the manual pages is conventional. There are manual pages for commands, programs, and programming functions (library routines). You will not see all of these titles on every manual page, as some of them only apply to certain types of commands.

Here are some titles you might see:

Last name: Name of the command described by the manual page.
Synopsis: A summary of the command and its syntax.
Configuration: Configuration details for a device.
The description: An explanation of what the program does.
Options: A description of the command line options accepted by the command.
Exit status: Possible values ​​of the output status of the order and what could lead to their use.
Return value: If the manual page is for a library routine, it describes the value that the library routine can return to the function that called that routine.
Errors: A list of values ​​that can be placed in errno In case of error.
Environment: A list of the environment variables that affect the command or program, and how.
Files: A list of files used by the command or program, such as configuration files.
Attributes: A summary of the different attributes of the command.
Versions: Details of versions of the Linux kernel or library where a system call or library function has appeared or changed significantly compared to previous versions.
Abide by: A description of all the standards to which the order could comply, such as POSIX.
Notes: Miscellaneous notes.
Bugs: Known issues.
Examples: One or more examples demonstrating the use of the command.
Authors: The people who wrote or maintained the order.
See also: Recommended reading related to the order or subject.

Men’s sections

If you scroll down a few pages, you see a list of sections in the manual.

The sections are:

General orders: Commands you use on the command line.
System calls: Functions that the kernel provides that a program can call.
Library functions: Function programs can call in code libraries (mainly the C standard).
Special files: Generally, devices, such as those found in / dev, and their drivers.
File formats and conventions: File formats, such as passwd, cron table, and tar archive files.
Games: Descriptions of commands, like fortune, that display quotes from a database when you run them.
Various: Descriptions of things like inodes, startup parameters, and the man himself.
System administration: Commands and daemons generally reserved for root to work with.
Kernel routines: Information relating to the internal functioning of the nucleus. This includes function interfaces and variables useful to programmers who write device drivers, for example. On most systems, this section is not installed.

When you see a command followed by a number, it refers to the description of that command in this section of the manual. For example, man (1) refers to the entry in the first section of the manual describing the man command.

In the image above, you see a reference to the man (7). This means that there is more information about the man in another section. When we first opened the manual page, it displayed man (1). If you type only man without a section number, man searches for all sections in order, looking for an entry for the command you typed. Of course, he found man (1) before man (7).

If you want to force man to search for an entry in a specific section, you must include the section number on the command line.

For example, we type the following to open the entry for humans in section seven:

man 7 man

The manual opens with the man entry in section seven.

This manual page provides instructions for writing manual pages. It describes the file format and macros that you can use to do some of the work for you. The man page (1) in the first section we looked at earlier describes how to use the man himself.

How to find entries in sections

Normally, if you just want to know how to use an order, you don’t have to give a section number. man will find the standard entry that describes how to use this command in the first section of the manual. Sometimes, however, you have to open an order entry in a particular section because you want different information.

You can easily find out which sections of the manual contain entries for an order. Each manual page has a title and a short description. The -f (whatis) option searches for page titles and returns a list of matches.

For this example, we type the following:

man -f man

The two man manual pages are listed with their section numbers and brief descriptions. Please note: some entries have the same name, but describe different commands and functions.

For example, we type the following:

man -f printf

It appears that two entries were found for printf: the first in the first section and another in the third section. However, these are different commands. The manual page in the first section describes the command line printf command, which output formats in the terminal window. The manual page for section three describes the printf library function family in the Programming language C.

It is also possible to browse the short descriptions, as well as the page titles. To do this, you use the -k (apropos) option. It will also match the occurrences of the search term inside other longer words.

We type the following:

man -k printf

Many of these commands are described in the same few manual pages because their main functionality is essentially the same. The vprintf man page describes the functionality of 10 of the commands listed in the image above.

You can take advantage of this feature to find information about what you’re trying to achieve, even if you don’t know the name of the command you want to use.

Suppose you want to change the password for a user account. We can search for all commands that mention “user” in the titles or descriptions of the manual pages. We can then direct it via grep to search for entries containing “password”.

To do this, we type the following:

man -k ‘user’ | grep password

Since we have placed the word “user” in single quotes and included a space at the end, it will only find matches for “user” and not “users”. A quick glance through the search results shows that the likely candidate is passwd.

Since this is a section manual page and we don’t need to include the section number in the command, we type the following:

passwd man

Let’s say we need a command that counts the number of words in a text file. We type the following to see if something like that exists:

man -k word | grep account

To find out everything about word counting, we type this command:

wc man

Speaking of wc, we can also use the -k (apropos) option with a single period (.) As the search target, which will match everything. If we channel this through wc and use the -l (lines) option, it will tell us how many manual pages there are on the computer.

To do all of this, we type the following command:

man -k. | wc -l

There are 6,706 manual pages on this Ubuntu computer, but don’t be surprised if the number is different on yours. It may vary depending on the software packages and utilities you have on your computer and the preinstalled manual pages.

Search page in a man

You can also search forward or backward from your current location in a manual page.

For this example, we type the following to open the manual page for the history command:

human story

To search forward, we press the forward slash (/), then type the word “event”. The search target appears at the bottom of the terminal window, and we press Enter to start the search.

The window displays the first result of all matches found and they are highlighted.

Press “n” to move between results at the bottom of the page. To search back in the manual page, press “N”; this will bring you back to the top of the page.

To turn highlighting on or off, press Esc + U.

If you are near the bottom of the manual page and want to search up, press the question mark (?), Then enter the search term. We searched for “entry”.

Again, all of the corresponding results are highlighted.

To find the next matching result, press “n” to move to the top of the manual page. Press “N” to go to the previous match result and move to the end of the manual page.

There is another way to find a man page. It hides all lines that do not match your search term. It is therefore preferable to use line numbers with this technique.

If we type “-N” and press Enter, we can see the line numbers in the manual page.

A manual page with line numbers in a terminal window.

We press the ampersand (&), enter our search term (number), then press Enter.

Only the lines containing our search term are displayed.

It’s easy to browse through them and spot those that look interesting. We think line 292 looks promising, so we want to go to this section of the manual page and check it out.

To review all the lines, we hit the ampersand (&), then hit Enter.

We type “292”, then “g” to access this line.

As soon as we type “g”, we are redirected to line 292 (this is why the “g” does not appear in the image above). Line 292 then appears at the top of the terminal window.

Line 292 at the top of the screen in a manual page in a terminal window.

You can press “-n” and press Enter to delete the line numbers.

Read the fabulous manual

There is a wealth of information in the manual pages. Even with commands you think you are familiar with, chances are there are other options you have never heard of.

You will also find commands that you did not know existed. With so many different ways to find and find information, it’s great to have everything on hand.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.