Man Command Usage With Examples For Linux and Unix – POFTUT

Man Command Usage With Examples For Linux and Unix

Linux man command is the number one helper to get more detailed information about Linux commands. There are different alternatives like info but man is a de-facto command for help. In this tutorial, we will look at various usage examples of the man command.

man Command Syntax

We will use following syntax for man command.

  • TERM is the command, utility, topic we want to open its man page.
  • OPTION is optional and used to provide optional to the man command.

View Man Page

The most common usage for man command is listing a command, tool, library usage simply. We will list the manual for ls command like below.

$ man ls
View Man Page
View Man Page

Man Page Sections

Manual pages are categorized into sections. Each command, tool, library have a section. Categorization is made according to the relevance of command, tool, library. Each section has a number from 1 to 9.

  1. Executable programs or shell commands
  2.  System calls (functions provided by the kernel)
  3.  Library calls (functions within program libraries)
  4. Special files (usually found in /dev)
  5. File formats and conventions eg /etc/passwd
  6. Games
  7. Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
  8. System administration commands (usually only for root)
  9. Kernel routines [Non-standard]

View Man Page For Specific Section

Sometimes there may be more than one tutorial about some expression. But those manual sections are different. For example print have more than one manual. We will look for section 1 manual with the example below.

$ man 1 printf
View Man Page For Specific Section
View Man Page For Specific Section

List Sections For A Command

We may want to list sections for a command, library, or function. We will use man pages file to search and list. In the example, we will look printf command manual pages.

$ man -aw printf
List Sections For A Command
List Sections For A Command

We can get section numbers from file name and directory name.

LEARN MORE  What Is Computer Network?

View All Man Pages For A Command

Another usage form for man pages is viewing all pages in a single command. Manual pages will be printed in a string mode. In order to quit from pages use q shortcut. We will use -a option to list all manual pages for printf command.

$ man -a printf

View Man Page In Browser

Another useful feature is viewing man pages in a browser. This is a more human-friendly way to read manuals but keep in mind that this will require a GUI desktop. First, we will set the BROWSER variable for the command line interface bash and then use -H parameter with the related command which is printf in this situation.

$ export BROWSER=/usr/bin/firefox
$ man -H printf

Search Man Page NAME Section

Man pages have different sections too. These are used to define part names. Here are these sections.

  • NAME contains the name of the command and short explanation
  • SYNOPSIS contains usage syntax
  • DESCRIPTION contains a more detailed explanation
  • OPTIONS contains all options about command
  • HISTORY contains history about the command and persons
$ man -f printf
Search Man Page NAME Section
Search Man Page NAME Section

Search Man Page NAME and DESCRIPTION Section

In the previous example, we have only searched in the NAME section. We may want to get more results and search in the DESCRIPTION section too. We will provide -k option like below.

$ man -k printf
Search Man Page NAME and DESCRIPTION Section
Search Man Page NAME and DESCRIPTION Section

Leave a Comment