Chapter 5 Lab - Getting Help
Chapter 5 Lab - Getting Help
Chapter 5 Lab - Getting Help
5.1 Introduction
This is Lab 5: Getting Help. By performing this lab, students will learn how to get help on
commands and find files.
In this task, you will explore the how to get help. This will be a very useful thing to know
how to do when you find yourself stuck or when you can't remember how a command
works.
In addition to Internet searches, the Linux Operating System provides a variety of
techniques to learn more about a given command or feature. Knowing these different
techniques will allow you to more easily and quickly find the answer you need.
5.2.1 Step 1
Execute commands in the bash shell by typing the command and then pressing the Enter key. For
example, type the following command to display today's date:
5.2.2 Step 2
To learn more about commands, access the manual page for the command with the man command.
For example, execute the following command to learn more about the date command:
If the man command can find the manual page for the argument provided, then that manual page will be
displayed using a command called less. The following table describes useful keys that can be used with the
less command to control the output of the display:
Key Purpose
H or h Display the help
Q or q Quit the help or manual page
Spacebar or f or Move a screen forward
PageDown
b or PageUp Move a screen backward
Enter or down arrow Move down one line
Up arrow Move up one line
/ followed by text to search Start searching forward
? followed by text to search Start searching backward
n Move to next text that matches search
N Move to previous matching text
5.2.3 Step 3
Type the letter h to see a list of movement commands. After reading the movement commands, type
the letter q to get back to the document.
Note that the man pages might be a bit of a mystery to you now, but as you learn more about Linux,
you will find they are a very valuable resource.
5.2.4 Step 4
Searches are not case sensitive and do not "wrap" around from the bottom to top, or vice versa. Start
a forward search for the word "file" by typing:
Note that what you are typing will appear at the bottom left portion of the screen.
5.2.5 Step 5
Notice that the text matching the search is highlighted. You can move forward to the next match by
pressing n. Also try moving backwards through the matches by pressing N:
5.2.6 Step 6
Use the movement commands previously described (such as using the spacebar to move down one
screen) to read the man page for the date command. When you are finished reading, type q to exit
the man page.
5.2.7 Step 7
In some cases you may not remember the exact name of the command. In these cases you can use
the -k option to the man command and provide a keyword argument. For example, execute the
following command to display a summary of all man pages that have the keyword "password" in
the description:
The -k option to the man command will often produce a huge amount of output. You will learn a
technique in a later lab to either limit this output or allow you to easily scroll though the data. For
now, just use the scrollbar on the right hand side of the terminal window to move the display up and
down as needed.
5.2.8 Step 8
Note that the apropos command is another way of viewing man page summaries with a keyword.
Type the following command:
Note: There is no difference between man -k and the apropos command.
5.2.9 Step 9
There are often multiple man pages with the same name. For example, the previous command
showed three pages for passwd. Execute the following command to view the man pages for the
word passwd:
The fact that there are different man pages for the same "name" is confusing for many beginning
Linux users. Man pages are not just for Linux commands, but also for system files and other
"features" of the Operating System. Additionally, there will sometimes be two commands with the
same name, as in the example provided above.
When you type a command such as man passwd, the first section is searched and, if a match is
found, the man page is displayed. The man -f passwd command that you previously executed
shows that there is a section 1 man page for passwd: passwd (1). As a result, that is the one that is
displayed by default.
5.2.10 Step 10
To display a man page for a different section, provide the section number as the first argument to
the man command. For example, execute the following command:
5.2.11 Step 11
Instead of using man -f to display all man page sections for a name, you can also use the whatis
command:
5.2.12 Step 12
Almost all system features (commands, system files, etc.) have man pages. Some of these features
also have a more advanced feature called info pages. For example, execute the following command:
Many beginning Linux users find info pages to be easier to read. They are often written more like
"lessons" while man pages are written purely as documentation.
5.2.13 Step 13
While viewing the info page from the previous step, type the letter h to see a list of movement
commands. Note that they are different from the movement commands used in man pages. After
reading the movement commands, type the letter l (lowercase L) to return to viewing the document.
5.2.14 Step 14
Use the movement commands to read the info page for the date command. When you are done, put
your cursor anywhere on the line that reads *Examples of date:: and then press the Enter key. A
new document will be displayed that shows examples of date.
5.2.15 Step 15
Type the l key to return to the previous screen. When you are finished reading, type q to exit the
info page.
5.2.16 Step 16
Another way of getting help is by using the --help option to a command. Most commands allow
you to pass an argument of --help to view basic command usage:
5.2.17 Step 17
Some system features also have more detailed help documents located in the /usr/share/doc
directory structure. Execute the following command to view the contents of this document:
Note that in almost all cases, the man pages and info pages will provide you with the information
that you need. However, if you need more in-depth information (something that system
administrators sometimes need), then you may find this information in the files located in the
/usr/share/doc directory.
In this task, we will explore how to search for a file on the system. This is useful to know in
situations when you can't find a file on the system, either one that you created or one that was
created by someone else.
5.3.1 Step 1
An easy way to search for a file is to use the locate command. For example, you can find the
location of the crontab file by executing the following command:
5.3.2 Step 2
Note that the output from the previous example includes files that have crontab as part of their
name. To find files that are just named crontab, use the following command:
Note: The locate command makes use of a database that is traditionally updated once per day
(normally in the middle of the night). This database contains a list of all files that were on the
system when the database was last updated.
As a result, any files that you created today will not normally be searchable with the locate
command. If you have access to the system as the root user (the system administrator account), you
can manually update this file by running the updatedb command. Regular users can not update the
database file.
Another possible solution to searching for "newer" files is to make use of the find command. This
command searches the live filesystem, rather than a static database. The find command isn't part of
the Linux Essentials objectives for this lab, so it is only mentioned here. Execute man find if you
want to explore this command on your own or wait for the lab that explores the find command.
5.3.3 Step 3
The whereis command only searches for commands and man pages, not just any file.
Recall from earlier that there is more than one passwd man page on the system. This is why you see
multiple file names and man pages (the files that end in .gz are man pages) when you execute the
previous command.