The β€œman” Command in Linux [6 Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

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.

man command in linux for ls command


Similar Readings


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.

Using -f option to find out short description

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.

section 7 of man command in linux

You can also see the man page of section 1 by using the man 1 man command a little bit.

Section 1 of man command in linux

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.

the -k option for the man command in linux to search in the entire manual

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


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.

All sections of intro command using -a option

man page of intro command

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.

Searching inside the manual page

searching for match for man command in linux

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

Rate this post
Md. Rafsan Zani

Hello, I’m Md. Rafsan Zani. I have recently completed my Undergraduate from the Bangladesh University of Engineering and Technology (BUET). Currently, I’m pursuing higher studies abroad. I’m really interested in computer science and would like to learn a lot about the wonderful world of computers. Currently, I’m working as a Linux Content Developer Executive and find Linux really interesting. I certainly would like to learn more about Linux and implement them in my future studies. Read Full Bio

Leave a Comment