Using the Command Line to get Help

«« Previous
Next »»

For this LPI objective of the Linux Essentials certification we will take a look at how we can obtain help from the Linux command line. Linux command line help may well be as simple as using the –help options to the program, or more details help from man or info pages.

Basic Linux Command Line Help


Many commands in Linux allow you to type in an option –help. If the long option is not supported -h may exists. Sometimes we can use /? to get the same results. If the option -h does not exist simple help may still be shown as the program does not understand the option you gave so showed simple usage instructions. Either way, it works and is often the first calling point for help.

Man Pages


Man or manual pages are the traditional longer help options, where we need mores detailed help. These pages are broken into sections. These sections help identify how the command may be used, for example as a standard user or as root.

◉ Section 1 : For help on if used as a standard user
◉ Section 5 : For help on the configuration file
◉ Section 8 : For help on using this as root

If you are into programming and API calls then sections 2 and 3 could be of interest too.

Other sections exit but these are most common. Using the command whatis (/usr/bin/whatis) it is easy to find man pages that exist for a given command:

whatis crontab

The output of this command shows that there are man page section 1 and 5 that exist for crontab. This can be seen clearly in the following screen-shot:

LPI Command Line, LPI Tutorials and Materials

If we specifically wanted to see the man pages for the crontab configuration files we could issue the command:

man 5 crontab

Likewise, specifically to access the help for using crontab as a user we could issue the command:

man 1 crontab

Although if no section was specified the lowest man page section is selected, so in this case section 1 is the default.

Once in a man page you can navigate using the arrow keys one line at a time or use the page up and page down keys to page up and down a page at a time. Using the / we can search for a string, (text), in the document, for example: /FILES would search for the text string FILES in the man page. When finished you can use the letter q to quit.

Info pages


Some commands may have info pages instead of, or in addition to, man pages. Info pages are accessed with the command info(/usr/bin/info). If a specific info page does not exist for a given command then /usr/bin/info will open the corresponding man page. The idea of the info pages is that they can be hyper-linked to provide for easier reading when the help manual is large.

info ls

The above command will open the info page for the command ls.

Which


The command which(/usr/bin/which) is a really useful command in Linux. Using this command we can search for executable programs or scripts that are located in the PATH variable. For example using the command:

which ls

The PATH variable is searched and starting at the first directory found in the PATH we look for the command ls. If it is not found the next directory is searched and so on. Using the -a option which will list all found occurrences of the given command, as such it does not stop the search on the first match.

which ls -a

Either with or without the -a option executable’s are only searched for within the PATH variable. This the same behaviour of running the program with just the program name, such as:

ls

If you need to run a program that is not within a directory located in the PATH variable you must include the file path to the program such as:

/usr/opt/myprogs/ls

Locating Man Pages and Programs


We have already seen that whatis can be used to locate man pages. Similarly we can use programs like man -k or apropos to list where the man pages are located. whereis will list the executable’s and man pages are for a given command.


«« Previous
Next »»

0 comments:

Post a Comment