LPI Linux Certification in a Nutshell (13 page)

Read LPI Linux Certification in a Nutshell Online

Authors: Adam Haeder; Stephen Addison Schneiter; Bruno Gomes Pessanha; James Stanger

Tags: #Reference:Computers

BOOK: LPI Linux Certification in a Nutshell
8.76Mb size Format: txt, pdf, ePub
Manpages

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.

Name

man

Syntax
man [
options
] [
section
]
name
Description

Format and display system manual pages from
section
on the topic of
name
. If
section
is omitted, the first manpage
found is displayed.

Frequently used options
-a

Normally,
man
exits after
displaying a single manpage. The
-a
option instructs
man
to display all
manpages that match
name
, in a
sequential fashion.

-d

Display debugging information.

-k

Search for manpages containing a given string.

-w

Print the locations of manpages instead of displaying
them.

Example 1

View a manpage for
mkfifo
:

$
man mkfifo
...

Results for the first manpage found are scrolled on the
screen.

Example 2

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.

Example 3

Display the
mkfifo
manpage from manual
section 3:

$
man 3 mkfifo
Manual sections

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
/dev
)

5

File formats

6

Games

7

Miscellaneous

8

System
administration

Note

Some systems might also have sections
9
,
n
, and
others, but only sections
1
through
8
are defined by the
FHS.

The order in which
man
searches the
sections for manpages is controlled by the
MANSECT
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 to
1:8:2:3:4:5:6:7:9:tcl:n:l:p:o
.

Manpage format

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
description

Synopsis

A complete description of syntax
or usage

Description

A brief description of the
item

Options

Detailed information on each
command-line option (for commands)

Return values

Information on function return
values (for programming references)

See also

A list of related items that may
be helpful

Bugs

Descriptions of unusual program
behavior or known defects

Files

A list of important files related
to the item, such as configuration files

Copying or
copyright

A description of how the item is
to be distributed or protected

Authors

A list of those who are
responsible for the item

man mechanics

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 your
man
configuration file,
/etc/man.config
. This file
contains directives to the
man
, telling it
where to search for pages (the
MANPATH
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
Objective 2: Process Text Streams Using Filters

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.

Name

cat

Syntax
cut
options
[
files
]
Description

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.

Frequently used options
-s

Never output more than one single blank line.

-v

Display nonprinting characters (these usually are not
displayed).

-A

Display nonprinting characters, display
$
at the end of each line, and display
Tab characters as
^I
.

Example

Send the contents of the file
/etc/passwd
to the file
/tmp/passwd
:

$
cat /etc/passwd > /tmp/passwd
Name

cut

Syntax
cut
options
[
files
]
Description

Cut out (that is, print) selected columns or fields from
one or more
files
. 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.

Frequently used options
-b
list

Print bytes in
list
positions.

-c
list

Print characters in
list
columns.

-d
delim

Set field delimiter (default is
;
).

-f
list

Print
list
fields.

Example

Show usernames (in the first colon-delimited field) from
/etc/passwd
:

$
cut -d: -f1 /etc/passwd
Name

expand

Syntax
expand [
options
] [
files
]
Description

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.

Frequently used options
-t
number

Specify Tab stops in place of the default 8.

-i

Initial; convert only at start of lines.

Name

fmt

Syntax
fmt [
options
] [
files
]
Description

Format text to a specified width by filling lines and
removing
newline characters. Multiple
files
from the command line are
concatenated.

Frequently used options
-u

Use uniform spacing:
one space between words and two spaces between
sentences.

-w
width

Set line width to
width
. The
default is 75 characters.

Name

head

Syntax
head [
options
] [
files
]
Description

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.

Frequently used options
-c
n

Print the first
n
bytes, or if
n
is followed by
k
or
m
, print the first
n
kilobytes or megabytes,
respectively.

-nn

Print the first
n
lines. The
default is 10.

Name

join

Syntax
join [
options
]
file1 file2
Description

Print a line for each pair of input lines, one each from
file1
and
file2
,
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.

Frequently used options
-j1
field

Join on
field
of
file1
.

-j2
field

Join on
field
of
file2
.

-j
field

Join on
field
of both
file1
and
file2
.

Example

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

Other books

Shadow Blade by Seressia Glass
Reality Boy by A. S. King
Island Intrigue by Wendy Howell Mills
The Dastardly Duke by Eileen Putman
Matadora by Steve Perry
Gloryland by Shelton Johnson
Rise of the Darklings by Paul Crilley
Don Juan Tenorio by José Zorrilla
One Unhappy Horse by C. S. Adler