Books collapsing with one another, symbolizing the Linux manual pages

The Linux Manual Pages – Man Command Explained

Hey There! Welcome!

In this lesson, we’ll explore the Linux manual pages and discover how they can make our command line experience a breeze! Let’s get started!

Discovering the Linux Manual Pages:

In our previous lesson, we explored the various ways we can use arguments and options to modify the behavior of a command.

But you might be thinking: “how on Earth am I supposed to remember all the different arguments and options for each command?”

  • Some are mandatory, while others are optional.

  • Some require long-form options, while others short-form.

  • Some options require arguments, while others do not.

Well, fear not, we have a trick up our sleeves!

Say hello to the Linux manual pages! Or, the “man pages” as they are otherwise known. This comprehensive collection of information describes how to use, maintain, and troubleshoot the various components that make up the Linux operating system.

Want to know more about a command? Linux manual pages to the rescue! Just type man, short for manual, followed by the command you’re curious about. For instance, let’s look up the ps command:

				
					ubuntu@ip-172-31-45-72:~$ man ps

NAME
       ps - report a snapshot of the current processes.

SYNOPSIS
       ps [options]

DESCRIPTION
       ps displays information about a selection of the active processes.  If
       you want a repetitive update of the selection and the displayed
       information, use top instead.

       This version of ps accepts several kinds of options:

       1   UNIX options, which may be grouped and must be preceded by a dash.
       2   BSD options, which may be grouped and must not be used with a dash.
       3   GNU long options, which are preceded by two dashes.

       Options of different types may be freely mixed, but conflicts can
       appear.  There are some synonymous options, which are functionally
       identical, due to the many standards and ps implementations that this
       ps is compatible with.
 Manual page ps(1) line 1 (press h for help or q to quit)

				
			

And just like that, a wealth of information has been displayed. Let’s break what we are looking at here:

  • At the very beginning we can see the name of our command along with a brief description.

  • Next, the synopsis section provides an overview of the command’s structure, showing the various arguments and options it accepts. In our case the ps command only accepts options. We’ll explore a more comprehensive synopsis section a bit later.

  • Following the synopsis section, we have a detailed description of our command, which provides general information and explains its intended purpose.

Deciphering the Manual Structure:

To view the remaining sections, we need to scroll down using the down arrow key on our keyboard.

				
					EXAMPLES
       To see every process on the system using standard syntax:
          ps -e
          ps -ef
          ps -eF
          ps -ely
...

				
			

Here we have a few practical examples that demonstrate how this command can be used. You might even recognize some from our previous lesson.

Let’s see what else we have next by scrolling down a bit more.

				
					SIMPLE PROCESS SELECTION
...
       -e     Select all processes.  Identical to -A.
...
       -u userlist
              Select by effective user ID (EUID) or name.  This selects the
              processes whose effective user name or ID is in userlist.

              The effective user ID describes the user whose file access
              permissions are used by the process (see geteuid(2)).  Identical
              to U and --user.
...
       --user userlist
              Select by effective user ID (EUID) or name.  Identical to -u and
              U.
				
			

Here we finally get to all the arguments and options that are available for this command along with a short description of their intended purpose. Jackpot!

Here we come across some of the options we used in our previous lesson, such as the -e option, which displays all available processes and a bit further down we can spot the -u option in both its short, and long form. Pretty cool right?

By examining the Linux manual pages in a similar way, we can discover new ways we can use a command or refresh our memory on arguments and options we’ve encountered before. In any case, these pages are sure to come in handy!

Feeling adventurous? Let’s keep scrolling.

				
					NOTES
       This ps works by reading the virtual files in /proc.  This ps does not
       need to be setuid kmem or have any privileges to run.  Do not give this
       ps any special permissions.
...
PROCESS FLAGS
       The sum of these values is displayed in the "F" column, which is
       provided by the flags output specifier:
...
PROCESS STATE CODES
       Here are the different values that the s, stat and state output
       specifiers (header "STAT" or "S") will display to describe the state of
       a process:
...

				
			

Here we have various notes, technical information, and other details you are not likely to need. Don’t worry if this information seems unintelligible—it’s highly technical, and you’re not expected to understand it unless you’re a specialized Linux programmer.

Time to wrap up our expedition! To exit the Linux manual pages we need to press the “q” key in our keyboard, instead of using the usual “Control” and “C” shortcut.

Understanding the Synopses Section:

Let’s delve into another command’s man page to better understand their structure.

This time, we’re going to explore the only other command you know about, the ping command. Just like before, let’s type man followed by ping:

				
					ubuntu@ip-172-31-45-72:~$ man ping

NAME
       ping - send ICMP ECHO_REQUEST to network hosts

SYNOPSIS
       ping [-aAbBdDfhLnOqrRUvV46] [-c count] [-F flowlabel] [-i interval]
            [-I interface] [-l preload] [-m mark] [-M pmtudisc_option]
            [-N nodeinfo_option] [-w deadline] [-W timeout] [-p pattern]
            [-Q tos] [-s packetsize] [-S sndbuf] [-t ttl]
            [-T timestamp option] [hop...] {destination}

DESCRIPTION
       ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit
       an ICMP ECHO_RESPONSE from a host or gateway.
...

				
			

The synopsis section looks a bit different this time, doesn’t it? Let’s break it down:

  • Anything within square brackets indicates that it’s optional, while anything within curly brackets denotes that it’s mandatory. In our case, all the options that ping accepts are optional, while the only argument it accepts is not.

  • Regarding option-arguments or parameters, options that do not accept them are specified at the very beginning, while options that do are specified separately. If the arguments for these options are underlined, that means they are mandatory.

  • Finally, it’s important to note that the order in which arguments and options appear matters. In this case, the ping command prefers that options are specified before arguments.

Meta-Manual for the Manual:

Curious about how we cracked the code on brackets, optional items, or the importance of order? Well, there is a manual for the manual itself believe it or not! Let’s take a look at it!

Let’s first exit by pressing q, and then, let’s type man man. No, it’s not a typo – that’s the actual command!

				
					ubuntu@ip-172-31-45-72:~$ man man

NAME
       man - an interface to the system reference manuals

SYNOPSIS
       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 ...

DESCRIPTION
       man  is  the system's manual pager.  Each page argument given to man is
       normally the name of a program, utility or function.  The  manual  page
       associated with each of these arguments is then found and displayed.  A
       section, if provided, will direct man to look only in that  section  of
       the  manual.   The  default action is to search in all of the available
       sections following a pre-defined order (see DEFAULTS), and to show only
       the first page found, even if page exists in several sections.
				
			

If we scroll slightly down, we can see information about each section, including how to read the synopsis section we learned about earlier.

If you have a kink for manuals or just have some time to spare, feel free to read all 532 lines – it’s a real page-turner! (You can find the online version here.)

Quick Help with '-h' or '--help':

But wait, we have one more trick up our sleeves! Most commands provide a way for users to view only the most essential information from their corresponding Linux manual pages, typically using an option such as -h. Let’s give it a go with the ping command:

				
					ubuntu@ip-172-31-45-72:~$ ping -h

Usage
  ping [options] <destination>

Options:
  <destination>      dns name or ip address
  -a                 use audible ping
  -A                 use adaptive ping
  -B                 sticky source address
  -c <count>         stop after <count> replies
  -D                 print timestamps
...

IPv6 options:
  -6                 use IPv6
  -F <flowlabel>     define flow label, default is random
  -N <nodeinfo opt>  use icmp6 node info query, try <help> as argument

For more details see ping(8).
ubuntu@ip-172-31-45-72:~$ 

				
			

Here it is! The output reveals only the options and arguments ping accepts, along with bite-sized descriptions.

Keep in mind however that the -h option might not work for all commands. That is because for some commands -h might perform some other function. Nevertheless, it’s a fantastic way of quickly viewing a command’s options and arguments. Neat, huh?

Final Thoughts:

And there you have it! You’re now well-versed in navigating the Linux manual pages.

With this newfound knowledge, let’s put your skills to the test. Your challenge is to use the manual pages to figure out which option limits the ping command to only 5 attempts when communicating with a destination. Dive in, and enjoy the exploration!

Fun Facts to brighten your day:

  • Time Travel with man: Ever wondered how Linux gurus seem to know everything? They don’t – they just use man. It’s like having a time machine that takes you back to the 90s, where manuals were the go-to for everything!

  • The ‘TL;DR’ Before It Was Cool: The -h option in many commands is the OG ‘too long; didn’t read’. It’s like the cliff notes for command line heroes.

  • Ancient Scrolls of Wisdom: man pages are like ancient scrolls – full of wisdom, but sometimes you need an archaeologist to decipher them.

  • The -h Option Roulette: Using -h can be like playing roulette – you never know if you’ll get a quick help or accidentally trigger an unknown command feature

  • The Never-Ending Story: Some man pages are so long, you might start wondering if they were written by J.R.R. Tolkien in his spare time.

Test Your Knowledge (Practice Quiz):

There has been error loading this quiz, please refresh the page or enable JavaScript to continue.

0/5

Take your Knowledge to the next level!

Learn the Linux command line with our interactive course!

Welcome back!

Don't have an account? Select the register button to create one!

First time around?

You're in the right place! Fill out the form to create your account: