Lab. 5
Lab. 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.
5.2.1 Step 1
Execute commands in the bash shell by typing the command and then pressing
theEnter key. For example, type the following command to display today's date:
date
sysadmin@localhost:~$ date
Tue Jan 19 17:27:20 UTC 2016
sysadmin@localhost:~$
5.2.2 Step 2
To learn more about commands, access the manual page for the command with
theman command. For example, execute the following command to learn more about
the date command:
man date
sysadmin@localhost:~$ man date
Your output should be similar to the following:
NAME
date - print or set the system date and time
SYNOPSIS
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
DESCRIPTION
Display the current time in the given FORMAT, or set the system
date.
-d, --date=STRING
display time described by STRING, not `now'
-f, --file=DATEFILE
like --date once for each line of DATEFILE
-r, --reference=FILE
display the last modification time of FILE
-R, --rfc-2822
output date and time in RFC 2822 format. Example:
Mon, 07 Aug
Manual page date(1) line 1 (press h for help or q to quit)
Note: Documents that are displayed with the man command are called "Man Pages".
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
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.
MOVING
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:
/file
Note that what you are typing will appear at the bottom left portion of the screen.
-r, --reference=FILE
display the last modification time of FILE
-R, --rfc-2822
output date and time in RFC 2822 format. Example:
Mon, 07 Aug
/file
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:
-f, --file=DATEFILE
like --date once for each line of DATEFILE
-r, --reference=FILE
display the last modification time of FILE
-R, --rfc-2822
output date and time in RFC 2822 format. Example:
Mon, 07 Aug
2006 12:34:56 -0600
--rfc-3339=TIMESPEC
output date and time in RFC 3339 format.
TIMESPEC=`date', `sec-
onds', or `ns' for date and time to the indicated
precision.
Date and time components are separated by a single
space:
2006-08-07 12:34:56-06:00
-s, --set=STRING
set time described by STRING
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 keywordargument. For example,
execute the following command to display a summary of all man pages that have the
keyword "password" in the description:
man -k password
sysadmin@localhost:~$ man -k password
chage (1) - change user password expiry information
chgpasswd (8) - update group passwords in batch mode
chpasswd (8) - update passwords in batch mode
cpgr (8) - copy with locking the given file to the
password or gr...
cppw (8) - copy with locking the given file to the
password or gr...
expiry (1) - check and enforce password expiration policy
login.defs (5) - shadow password suite configuration
pam_pwhistory (8) - PAM module to remember last passwords
pam_unix (8) - Module for traditional password authentication
passwd (1) - change user password
passwd (1ssl) - compute password hashes
passwd (5) - the password file
pwck (8) - verify integrity of password files
pwconv (8) - convert to and from shadow passwords and groups
shadow (5) - shadowed password file
shadowconfig (8) - toggle shadow passwords on and off
unix_chkpwd (8) - Helper binary that verifies the password of the
curren...
unix_update (8) - Helper binary that updates the password of a
given user
vipw (8) - edit the password, group, shadow-password or
shadow-gr...
sysadmin@localhost:~$
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:
apropos password
sysadmin@localhost:~$ apropos password
chage (1) - change user password expiry information
chgpasswd (8) - update group passwords in batch mode
chpasswd (8) - update passwords in batch mode
cpgr (8) - copy with locking the given file to the
password or gr...
cppw (8) - copy with locking the given file to the
password or gr...
expiry (1) - check and enforce password expiration policy
login.defs (5) - shadow password suite configuration
pam_pwhistory (8) - PAM module to remember last passwords
pam_unix (8) - Module for traditional password authentication
passwd (1) - change user password
passwd (1ssl) - compute password hashes
passwd (5) - the password file
pwck (8) - verify integrity of password files
pwconv (8) - convert to and from shadow passwords and groups
shadow (5) - shadowed password file
shadowconfig (8) - toggle shadow passwords on and off
unix_chkpwd (8) - Helper binary that verifies the password of the
curren...
unix_update (8) - Helper binary that updates the password of a
given user
vipw (8) - edit the password, group, shadow-password or
shadow-gr...
sysadmin@localhost:~$
man -f passwd
sysadmin@localhost:~$ man -f passwd
passwd (5) - the password file
passwd (1) - change user password
passwd (1ssl) - compute password hashes
sysadmin@localhost:~$
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.
The different man pages are distinguished by "sections". By default there are nine default
sections of man pages:
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:
man 5 passwd
PASSWD(5) File Formats and Conversions
PASSWD(5)
NAME
passwd - the password file
DESCRIPTION
/etc/passwd contains one line for each user account, with seven
fields
delimited by colons (":"). These fields are:
o login name
o numerical user ID
o numerical group ID
whatis passwd
sysadmin@localhost:~$ whatis passwd
passwd (5) - the password file
passwd (1) - change user password
passwd (1ssl) - compute password hashes
sysadmin@localhost:~$
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:
info date
File: coreutils.info, Node: date invocation, Next: arch invocation,
Up: Syst\
em context
Synopses:
Normally, `date' uses the time zone rules indicated by the `TZ'
environment variable, or the system default rules if `TZ' is not set.
*Note Specifying the Time Zone with `TZ': (libc)TZ Variable.
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 qto
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:
date --help
sysadmin@localhost:~$ date --help
Usage: date [OPTION]... [+FORMAT]
or: date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date.
ls /usr/share/doc
sysadmin@localhost:~$ ls /usr/share/doc
adduser libdrm2 libx11-data
apt libedit2 libxau6
ascii libelf1 libxcb1
base-files libffi6 libxdmcp6
base-passwd libgcc1 libxext6
bash libgcrypt11 libxml2
bind9 libgdbm3 libxmuu1
bind9-host libgeoip1 locales
bind9utils libgettextpo0 login
bsdmainutils libglib2.0-0 logrotate
bsdutils libgnutls26 lsb-base
busybox-initramfs libgomp1 makedev
bzip2 libgpg-error0 man-db
ca-certificates libgpm2 mawk
coreutils libgssapi-krb5-2 mc
cpio libgssapi3-heimdal mc-data
cron libhcrypto4-heimdal mime-support
curl libheimbase1-heimdal mlocate
dash libheimntlm0-heimdal module-init-tools
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.
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:
locate crontab
sysadmin@localhost:~$ locate crontab
/etc/crontab
/usr/bin/crontab
/usr/share/doc/cron/examples/crontab2english.pl
/usr/share/man/man1/crontab.1.gz
/usr/share/man/man5/crontab.5.gz
sysadmin@localhost:~$
5.3.2 Step 2
Note that the output from the previous example includes files that have crontabas part of
their name. To find files that are just named crontab, use the following command:
locate -b "\crontab"
sysadmin@localhost:~$ locate -b "\crontab"
/etc/crontab
/usr/bin/crontab
sysadmin@localhost:~$
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
thelocate 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 updatedbcommand. Regular users can not update the database file.
5.3.3 Step 3
You may just want to find where a command (or its man pages) is located. This can be
accomplished with the whereis command :
whereis passwd
sysadmin@localhost:~$ whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz
/usr/share/man/man1/passwd.1ssl.gz /usr/share/man/man5/passwd.5.gz
sysadmin@localhost:~$
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.