Untitled Document
man Command

The synatx of some UNIX / Linux command can still be confusing - even to expert .One cannot remember either the command or the required option that will perform a specific job . This is quite understandable considering that there are several hundred commands in /bin and /usr/bin on nay UNIX / Linux system .

UNIX / Linux offers an online help facility in the man command . man displays the documentation - often called the man documentation - of practically every command on the system . For example to seek help on the wc command , simply run man with wc as an argument .

1. Basic Example -

Run below command , The entire man page for wc is dumped on the screen .

   man wc 
 ----------------------- OUTPUT OF MAN COMMAND ----------------------------------
  User Commands                                 wc (1)
       WC - display a count of lines , words and characters in a file 
       WC [ -c | -m | -C | [ -lw ] [ file ... ]
       The wc utility reads one or more input files and , by default , writes the number of newline characters , words and 
       bytes contained in each input file to the standard output.The utility also writes a total count for all named files,
       if more than one input file is specified .
       We considers a word to be a  non-zero-length string of characters delimited by white space ( for example , SPACE , TAB ).
       See iswspace(3C) os isspace (3C) .
       The following options are supported :
       -c     Count bytes.
       -m     Count Characters.
       -C     Same as -m.
       -l     Count lines.
       -w     Count words delimited by white space characters or new 
              line characters . Delimiting characters are expected 
              Unix Code (EUC) characters from any code set defined 
              by iswspace().
       If no option is specified the default is -lwc ( count lines , words and bytes. )
       The following operand is supported :
       file A path name of an input file . If no file operands are specified , the standard input will be used .
       See lagefile(5) for the description  of the behaviour of the wc when
       encountering files greater than or equal to 2 Gbyte (2 **31 bytes ).
       The following exit values are returned:
       0      Successful Completion.
       >0     An Error occured .
       cksum(1),     isspace(3C),     iswalpha(3C),     iswspace(3C),      setlocale(3C),     attributes(5),
       environ(5),      largefile(5)


man represents the first page and pauses . It does this by sending its output to a pager program , which displays this output one page ( screen) at a time . The pager is actually a UNIX / Linux command , and man is always preconfigured to be used with a specific pager . UNIX / Linux system currently uses these pager programs :

  • more - Berkely's pager which is available in almost all unix and linux system . We will consider more in this text .
  • less - The standard pager used in Linux system , which is advanced pager than more and has good search and replace features like vi

On a an page that uses more as the pager , you will see a prompt at the bottom-left of the screen which looks something like this :


At this prompt you can press a key to perform navigation , or search for a string . The key you press is interpreted as one of man's ( rather , the pager's) internal commands , and the character often doesn't show up on the screen .

To quit the pager, and ultimately man press q . You will be returned the shell's prompt .


Navigation and Search -

There are numerous navigation commands and vary across UNIX and Linux system implementation . For time being , we should know these two commands whcih should work on all systems :

  • f or spacebar - Advances the display by one screen of text at a time .
  • b - which moves back one screen .

The man documentation is sometimes quite extensive , and the search facility lets you locate a page containing a keyword quite easily . For example , you can up the page containing the word process by using the string with the / ( frontslash )

   /process [enter] 

The / and search string show up on the screen this time , and when you press [Enter] , you are taken to the page containing process . If that's not the page you are looking for , you can repeat the search by pressing n .

Understanding The man Documentation -

A man page is divided into a number of compulsory and optinal sections . Every command doesn't have all sections , but the first three ( NAME,SYNOPSIS and DESCRIPTION ) are generally seen in all man pages . NAME presents a one-line introduction to the command .SYNOPSIS shows the syntax used by the command , and DESCRIPTION ( often the largest section ) provides a detailed description .

The SYNOPSIS section is the one that we need to examine closely, and we will do that with reference to the man page of the wc command as shown in above man page output .Here you will find the syntax - the options and arguments used with the command .The SYNOPSIS follows certain conventions and rules which every user must understand .

  • If a command argument is enclosed in rectangular brackets , then it is optional ; otherwise , the argument is required . The wc man page shoows all of its arguments enclosed in three such groups. This means that wc can be used without arguments .
  • The ellipsis ( a set of three dots ) implies that there can be more instances of the preceding word. The expression [ file ... ] signifies that wc can be used with more than one filename as argument .
  • If you find the | character in any of these areas , it means that only one of the option shown on either side of the pipe can be used . Here , only one of the options , -c , -m , -C can be used .

All options used by the command are listed in the OPTIONS sections. Often , difficult options are supported by suitable examples . There is a separate section named EXIT STATUS which lists possible error conditions and their numeric representation . You need to understand the significance of these numbers when writing shell scripts in order to determine the actual cause of termination of a command .

2. man command with ( -k ) option -

The POSIX specification rerquires man to support only one option ( -k ) . When used with this option , man searches a summary database and prints a one-line description of the command . To know what awk does, use man command as below :

   man -k awk 
   Output :
   awk            awk(1)          - pattern scanning and processing language 
   nawk           nawk(1)         - pattern scanning and processing language  

man locates its argument from the NAME line of all man pages nawk is a newer version of awk that is generally found on all modern UNIX / Linux system . Once you know that awk is a processing language, you can use man awk to view its detailed documentation .
Untitled Document