Read LPI Linux Certification in a Nutshell Online
Authors: Adam Haeder; Stephen Addison Schneiter; Bruno Gomes Pessanha; James Stanger
Tags: #Reference:Computers
Traditional computer manuals covered everything from
physical maintenance to programming libraries. Although the books were
convenient, many users didn’t always want to dig through printed
documentation or carry it around. So, as space became available, the
man
(
manual
)
command was created to put the books on the system, giving users
immediate access to the information they needed in a
searchable
, quick-reference format.
There is a
manpage
for most commands on your
system. There are also manpages for important files, library functions,
shells, languages, devices, and other features.
man
is to your system what a dictionary is to your written language. That
is, nearly everything is defined in detail, but you probably need to
know in advance just what you’re looking for.
man
man [options
] [section
]name
Format and display system manual pages fromsection
on the topic ofname
. Ifsection
is omitted, the first manpage
found is displayed.
Normally,
man
exits after
displaying a single manpage. The
-a
option instructs
man
to display all
manpages that matchname
, in a
sequential fashion.
Display debugging information.
Search for manpages containing a given string.
Print the locations of manpages instead of displaying
them.
View a manpage for
mkfifo
:
$man mkfifo
...
Results for the first manpage found are scrolled on the
screen.
Determine what manpages are available for
mkfifo
:
$man -wa mkfifo
/usr/share/man/man1/mkfifo.1
/usr/share/man/man3/mkfifo.3
This shows that two manpages are available, one in section 1
(
mkfifo.1
) of the manual and another in section
3 (
mkfifo.3
). See the next section for a
description of manpage sections.
Display the
mkfifo
manpage from manual
section 3:
$man 3 mkfifo
Manpages are grouped into
sections
, and there are times
when you should know the appropriate section in which to search for
an item. For example, if you were interested in the
mkfifo
C-language
function rather than the
command, you must tell the
man
program to
search the section on library functions (in this case, section 3,
Linux Programmer’s Manual
):
$man 3 mkfifo
An alternative would be to have the
man
program search all manual sections:
$man -a mkfifo
The first example returns the
mkfifo(3)
manpage regarding the library function. The second returns pages for
both the command and the function. In this case, the pages are
delivered separately; terminating the pager on the first manpage
with Ctrl-C causes the second to be displayed.
Manual sections are detailed in
Table 6-3
.
Table 6-3. Man sections
Section | Description |
---|---|
1 | User programs |
2 | System calls |
3 | Library calls |
4 | Special files (usually found in |
5 | File formats |
6 | Games |
7 | Miscellaneous |
8 | System |
Some systems might also have sections9
,n
, and
others, but only sections1
through8
are defined by the
FHS.
The order in which
man
searches the
sections for manpages is controlled by theMANSECT
environment variable.MANSECT
contains a colon-separated list of
section numbers. If it is not set,
man
(as of
version 1.5k) behaves as if it were set to1:8:2:3:4:5:6:7:9:tcl:n:l:p:o
.
Most manpages are presented in a concise format with
information grouped under well-known standard headings such as those
shown in
Table 6-4
. Other manpage
headings depend on the context of the individual manpage.
Table 6-4. Standard manpage headings
Heading | Description |
---|---|
Name | The name of the item, along with a |
Synopsis | A complete description of syntax |
Description | A brief description of the |
Options | Detailed information on each |
Return values | Information on function return |
See also | A list of related items that may |
Bugs | Descriptions of unusual program |
Files | A list of important files related |
Copying or | A description of how the item is |
Authors | A list of those who are |
System manpages are stored mostly in
/usr/share/man
, but may exist in other places
as well. At any time, the manual pages available to the
man
command are contained within directories
configured in yourman
configuration file,
/etc/man.config
. This file
contains directives to the
man
, telling it
where to search for pages (theMANPATH
directive), the paging program to
use (PAGER
), and many others.
This file essentially controls how
man
works on
your system. To observe this, use the debug
(
-d
) option to
man
to
watch as it constructs a
manpath
(a directory search list)
and prepares to display your selection:
$man -d mkfifo
Many of the commands on Linux systems are intended to be
used as
filters
, meaning that multiple commands can
be piped together to perform complex operations on text. Text fed into the
command’s standard input or read from files is modified in some useful way
and sent to standard output or to a new file, leaving the original source
file unmodified. Multiple commands can be combined to produce
text streams
, which modify text at each
step. This section describes basic use and syntax for the filtering
commands important for Exam 101. Refer to a Linux command reference for
full details on each command and the many other available commands.
cat
cutoptions
[files
]
Concatenate files and print on the standard output. Cat
is often used as the first command in a text stream, as it simply
sends the contents of a file (or multiple files) to the standard
output.
Never output more than one single blank line.
Display nonprinting characters (these usually are not
displayed).
Display nonprinting characters, display$
at the end of each line, and display
Tab characters as^I
.
Send the contents of the file
/etc/passwd
to the file
/tmp/passwd
:
$cat /etc/passwd > /tmp/passwd
cut
cutoptions
[files
]
Cut out (that is, print) selected columns or fields from
one or morefiles
. The source file is not
changed. This is useful if you need quick access to a vertical
slice of a file. By default, the slices are delimited by
a Tab character.
list
Print bytes inlist
positions.
list
Print characters inlist
columns.
delim
Set field delimiter (default is;
).
list
Printlist
fields.
Show usernames (in the first colon-delimited field) from
/etc/passwd
:
$cut -d: -f1 /etc/passwd
expand
expand [options
] [files
]
Convert Tabs to spaces. Sometimes the use of
Tab characters can make output that is attractive on one
output device look bad on another. This command eliminates Tabs and
replaces them with the equivalent number of spaces. By default, Tabs
are assumed to be eight spaces apart.
number
Specify Tab stops in place of the default 8.
Initial; convert only at start of lines.
fmt
fmt [options
] [files
]
Format text to a specified width by filling lines and
removing
newline characters. Multiplefiles
from the command line are
concatenated.
Use uniform spacing:
one space between words and two spaces between
sentences.
width
Set line width towidth
. The
default is 75 characters.
head
head [options
] [files
]
Print the first few lines of one or more files (the
“head” of the file or files). When more than one file is specified, a
header is printed at the beginning of each file, and each is listed in
succession.
n
Print the firstn
bytes, or ifn
is followed byk
orm
, print the firstn
kilobytes or megabytes,
respectively.
-nn
Print the firstn
lines. The
default is 10.
join
join [options
]file1 file2
Print a line for each pair of input lines, one each fromfile1
andfile2
,
that have identical
join fields
. This function could be
thought of as a very simple database table join, where the two files
share a common index just as two tables in a database would.
field
Join onfield
offile1
.
field
Join onfield
offile2
.
field
Join onfield
of bothfile1
andfile2
.
Suppose
file1
contains the
following:
1 one
2 two
3 three
and
file2
contains:
1 11
2 22
3 33
Issuing the command:
$join -j 1 file1 file2
yields the following output:
1 one 11
2 two 22
3 three 33