The man command in Linux is used to display the manual of using a particular command. This command shows the available options, syntax, and much other information. To understand a Linux bash command, you will undoubtedly need to have a look at the manual of that command. Certainly, this is one of the most used commands in Linux bash.
A. Description
The man command stands for manual. The man command in Linux will display a manual page or documentation of a Linux command. This command displays information like the synopsis, description, options, exit status, authors, copyright, etc. But generally, users use this command to find out about different options available for the command.
B. Syntax
The syntax of the man command in Linux looks a bit difficult, itβs actually quite simple. It generally takes a command and shows information about that command.
man [man options] [[section] page ...] ...
man -k [apropos options] regexp ...
man -K [man options] [section] term ...
man -f [whatis options] page ...
man -l [man options] file ...
man -w|-W [man options] page β¦
Note: All the options are optional and in most cases, you will not use any options, but rather find the required text from the manual page.
C. Options
There are many options available for the man command in Linux. Here are some of the most used options for the man command. If you want to find in detail the options available for the man command use the man page.
man man
- SECTION COMMAND (Shows the specific SECTION of a COMMAND)
- -k KEYWORD (Search for the KEYWORD in the whole manual page and shows all the matches)
- -f KEYWORD (Look for a short description of any KEYWORD or Command)
- -d, –default (Resets the man command behavior to default)
- -i, –ignore-case (Ignore case sensitivity of the command)
- -I, –match-case (Looking inside the man page with case sensitivity)
- -a, –all (Shows all manual pages that match the specific keyword or command)
Note: The options are case-sensitive and some options can fill up the whole command line, so piping with less command is recommended.
Practical Examples of the βmanβ Command in Linux
The main objective of the man command is to look into options available for a particular command. But this command can also look into the manual for any texts or keyphrases. This is an important command with many practical uses and youβll spend a lot of time in this command to work in Linux.
Example 1: Using the βmanβ Command to Show the Manual Page of a Command
This is the main function of the man command. You will use the man command for this purpose most of the time. The general syntax is also quite simple.
man COMMAND
You can try this man command for the ls command which is another popular and widely used command following the steps below.
Steps to Follow >
βΆ Open the Terminal in the Home directory. Any directory is fine for this command, but when you open Terminal, by default, the starting directory will be the Home directory.
β· Type the following command.
man ls
βΈ Press the ENTER key.
Note: To get out of the man page, you need to press the q key from the keyboard.
Output >
As you can see, the manual page for the ls command is shown in the command line.
Similar Readings
- The “history” Command in Linux [6 Practical Examples]
- The βcalβ Command in Linux [7 Practical Examples]
- The βbcβ Command in Linux [10+ Practical Examples]
Example 2: Displaying a Short Description of a Command Using the βmanβ Command
To view a short description of a command, you need to use the -f option. This option will show you all the sections available and a short description of every one of these command sections.
The general syntax is as follows.
man -f COMMAND
To use this command, you need to follow the steps below.
Steps to Follow >
βΆ Open the Terminal in the Home directory.
β· Suppose you want to view the manual of the ls command. Type the following command in the command line.
man -f ls
βΈ Press the ENTER key.
Output >
Here you will see all the sections and a short description of the ls command.
Example 3: Showing a Particular Section of a Command Using the βmanβ Command
Sometimes, one command has different functions These functions are written on the manual page in different sections. You can see the sections using the -f option in the previous example. To access the manual page of a certain command, you have to follow the general syntax below.
man SECTION_NUM COMMAND
man COMMAND.SECTION_NUM
Not all commands have different sections. In fact, only a handful of commands have this type of different functionality. The man command itself has this feature It has section 1 and section 7.
You can follow the steps below to have a try.
Steps to Follow >
βΆ Open the Terminal in the Home directory.
β· There are 2 syntaxes to access different sections of the man command. Type any of the following to see section 7 of the manual page of the man command.
man 7 man
man man.7
βΈ Press the ENTER key.
Output >
You can see that the image below shows section 7 of the man page.
You can also see the man page of section 1 by using the man 1 man command a little bit.
Example 4: Searching for a Keyphrase/Text in the Entire Manual Using the βmanβ Command
You can search for a text, keyphrase, or command inside the entire manual if you want. You just need to use the -k option to do that. The general syntax is as follows.
man -k PHRASE
You can try this for the ls command by following the steps below.
Steps to Follow >
βΆ Open the Terminal in the Home directory.
β· Type the command below to find all the matches with the ls command.
man -k ls
βΈ Press the ENTER key.
Output >
As you can see, the command line shows all the matches with the ls command available.
Note: Sometimes the number of matches is too large and the command line will be completely filled with texts. In that case, you can pipe the command with the less command for an interactive view.
Similar Readings
- The βcronβ Command in Linux [3 Practical Examples]
- The βcrontabβ Command in Linux [10 Practical Examples]
- The βdateβ Command in Linux [8+ Practical Examples]
- The βncalβ Command in Linux [8 Practical Examples]
Example 5: Displaying All the Manual Pages of Different Sections Using the βmanβ Command
Some commands have many sections and you may want to view all of these sections one after another. In that case, you need to use the -a option to view all the different manual pages of the particular command. The general syntax is as follows.
man -a COMMAND
Now you can view all the different sections of the intro command which have many sections. Try using the steps below.
Steps to Follow >
βΆ Open the Terminal in the Home directory.
β· Type the following command to view the first section of the intro command.
man -a intro
βΈ Now, you will get inside the man page of the first section of the intro command.
βΉ Press q to quit this section.
βΊ Now you will have a prompt that asks you to press Return/ENTER to go to the next section, press CTRL+D to skip the next section, and press CTRL+C to quit the command.
β» Press the ENTER key.
Output >
As you can see, in the command line you will be able to select which section you want to choose and when you get inside one of these sections, you will find the man page and its content.
Example 6: Searching for a Particular Keyphrase/Text in the Manual Page
The man page of a command is not small. Sometimes itβs too large to find the particular information. In that case, you have to search for a particular keyphrase or Text from the man page. All you have to do is type(/) and write the text you want to search for. You can follow the steps below.
Steps to Follow >
βΆ Open the Terminal in the Home directory.
β· Type the following command to open the manual page of the ls command.
man ls
βΈ Now on the manual page type (/) and then type the keyphrase you want to search. Suppose you want to search the keyphrase βfileβ. Just type /file.
βΉ Press the ENTER key. You will find the matches of the file on the manual page.
βΊ You can navigate and get to the next mention of the file using n and the previous mention using b. If you want to quit, just press q.
Note: On the man page you can get to the next or previous line by pressing the arrow keys. To get to the next page, press the SPACE bar.
Output >
You can search and navigate through the man page like the following images.
Note: The matches are not case-sensitive, so you donβt need to worry about that.
Conclusion
The man command is one of the most useful commands to understand new commands. This command can show the syntax, options, and much other information about another command and will help you understand it with examples. I highly recommend you get used to this command and use the search option to search for any options that may be helpful to you.
Similar Readings
- The βneofetchβ Command in Linux [12+ Practical Examples]
- The βtreeβ Command in Linux [14 Practical Examples]
- The βwhatisβ Command in Linux [12 Practical Examples]
- The βwhereisβ Command in Linux [10 Practical Examples]
- The βwhichβ Command in Linux [3 Practical Examples]
- The βatβ Command in Linux [7 Practical Examples]
- The βteeβ Command in Linux [4 Practical Examples]
FUNDAMENTALS A Complete Guide for Beginners