Read LPI Linux Certification in a Nutshell Online
Authors: Adam Haeder; Stephen Addison Schneiter; Bruno Gomes Pessanha; James Stanger
Tags: #Reference:Computers
nl
nl [options
] [files
]
Number the lines offiles
,
which are concatenated in the output. This command is used for
numbering lines in the body of text, including special header and
footer options normally excluded from the line numbering. The
numbering is done for each
logical page
, which is defined as
having a header, a body, and a footer. These are delimited by the
special strings\:\:\:
,\:\:
, and\:
, respectively.
style
Set body numbering style tostyle
, which ist
by default (styles are described
next).
style
Set footer number style tostyle
(n
by default).
style
Set header numbering style tostyle
, (n
by default).
Styles can be in these forms:
Number all lines.
Number only nonempty lines.
Do not number lines.
REGEXP
Number only lines that contain a match for regular
expressionREGEXP
.
Suppose file
file1
contains the following
text:
\:\:\:
header
\:\:
line1
line2
line3
\:
footer
\:\:\:
header
\:\:
line1
line2
line3
\:
footer
If the following command is given:
$nl -h a file1
the output would yield numbered headers and body lines but no
numbering on footer lines. Each new header represents the beginning of
a new logical page and thus a restart of the numbering
sequence:
1 header
2 line1
3 line2
4 line3
footer
1 header
2 line1
3 line2
4 line3
footer
od
od [options
] [files
]
Dump files in octal and other formats. This program
prints a listing of a file’s contents in a variety of formats. It is
often used to examine the byte codes of binary files but can be used
on any file or input stream. Each line of output consists of an octal
byte offset from the start of the file followed by a series of tokens
indicating the contents of the file. Depending on the options
specified, these tokens can be ASCII, decimal, hexadecimal, or octal
representations of the contents.
type
Specify thetype
of
output.
Typical types include:
Named character
ASCII character or backslash escape
Octal (the default)
Hexadecimal
If
file1
contains:
a1\n
A1\n
where\n
stands for the
newline character, the
od
command specifying
named characters yields the following output:
$od -t a file1
00000000 a 1 nl A 1 nl
00000006
A slight nuance is the ASCII character mode. This
od
command specifying named characters yields the
following output with backslash-escaped characters rather than named
characters:
$od -t c file1
00000000 a 1 \n A 1 \n
00000006
With numeric output formats, you can instruct
od
on how many bytes to use in interpreting each
number in the data. To do this, follow the type specification by a
decimal integer. This
od
command specifying
single-byte hex results yields the following output:
$od -t x1 file1
00000000 61 31 0a 41 31 0a
00000006
Doing the same thing in octal notation yields:
$od -t o1 file1
00000000 141 061 012 101 061 012
00000006
If you examine an ASCII chart with hex and octal
representations, you’ll see that these results match those
tables.
paste
paste [options
] [files
]
Paste together corresponding lines of one or morefiles
into vertical columns. Similar in
function to the
join
command, but simpler in
scope.
n
Separate columns with charactern
in place of the default Tab.
Merge lines from one file into a single line. When
multiple files are specified, their contents are placed on
individual lines of output, one per file.
For the following three examples,
file1
contains:
1
2
3
and
file2
contains:
A
B
C
A simple
paste
creates columns from each
file in standard output:
$paste file1 file2
1 A
2 B
3 C
The column separator option yields columns separated by the
specified character:
$paste -d'@' file1 file2
1@A
2@B
3@C
The single-line option (
-s
) yields a line
for each file:
$paste -s file1 file2
1 2 3
A B C
pr
pr [options
] [file
]
Convert a text file into a paginated, columnar version,
with headers and page fills. This command is convenient for yielding
nice output, such as for a line printer from raw, uninteresting text
files. The header will consist of the date and time, the filename, and
a page number.
Double space.
header
Useheader
in place of the
filename in the header.
lines
Set page length tolines
. The
default is 66.
width
Set the left margin towidth
.
sort
sort [options
] [files
]
Write input to
stdout
(standard
out), sorted alphabetically.
Case-insensitive sort.
POS1
[,POS2
]Sort on the key starting atPOS1
and (optionally) ending atPOS2
.
Sort numerically.
Sort in reverse order.
SEP
UseSEP
as the key separator.
The default is to use whitespace as the key separator.
Sort all processes on the system by resident size (RSS
inps
):
$ps aux | sort -k 6 -n
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2 0.0 0.0 0 0 ? SW Feb08 0:00 [keventd]
root 3 0.0 0.0 0 0 ? SWN Feb08 0:00 [ksoftirqd_CPU0]
root 4 0.0 0.0 0 0 ? SW Feb08 0:01 [kswapd]
root 5 0.0 0.0 0 0 ? SW Feb08 0:00 [bdflush]
root 6 0.0 0.0 0 0 ? SW Feb08 0:00 [kupdated]
root 7 0.0 0.0 0 0 ? SW Feb08 0:00 [kjournald]
root 520 0.0 0.3 1340 392 tty0 S Feb08 0:00 /sbin/mingetty tt
root 335 0.0 0.3 1360 436 ? S Feb08 0:00 klogd -x
root 1 0.0 0.3 1372 480 ? S Feb08 0:18 init
daemon 468 0.0 0.3 1404 492 ? S Feb08 0:00 /usr/sbin/atd
root 330 0.0 0.4 1424 560 ? S Feb08 0:01 syslogd -m 0
root 454 0.0 0.4 1540 600 ? S Feb08 0:01 crond
root 3130 0.0 0.5 2584 664 pts/0 R 13:24 0:00 ps aux
root 402 0.0 0.6 2096 856 ? S Feb08 0:00 xinetd -stayalive
root 385 0.0 0.9 2624 1244 ? S Feb08 0:00 /usr/sbin/sshd
root 530 0.0 0.9 2248 1244 pts/0 S Feb08 0:01 -bash
root 3131 0.0 0.9 2248 1244 pts/0 R 13:24 0:00 -bash
root 420 0.0 1.3 4620 1648 ? S Feb08 0:51 sendmail: accepti
root 529 0.0 1.5 3624 1976 ? S Feb08 0:06 /usr/sbin/sshd
split
split [option
] [infile
] [outfile
]
Splitinfile
into a specified
number of line groups, with output going into a succession of files,outfile
aa
,outfile
ab
, and so on (the default is
xaa
,
xab
, etc.). Theinfile
remains unchanged. This command is
handy if you have a very long text file that needs to be reduced to a
succession of smaller files. This was often done to email large files
in smaller chunks, because at one time it was considered bad practice
to a send a single large email message.
Split theinfile
inton
-line segments. The default is
1,000.
Suppose
file1
contains:
1 one
2 two
3 three
4 four
5 five
6 six
Then the command:
$split -2 file1 splitout_
yields as output three new files,
splitout_aa
,
splitout_ab
,
and
splitout_ac
.
The file
splitout_aa
contains:
1 one
2 two
splitout_ab
contains:
3 three
4 four
and
splitout_ac
contains:
5 five
6 six
tac
tac [file
]
This command is named as an opposite for the
cat
command, which simply prints text files to
standard output. In this case,
tac
prints the
text files to standard output with lines in reverse order.
Suppose
file1
contains:
1 one
2 two
3 three
Then the command:
$tac file1
yields as output:
3 three
2 two
1 one
tail
tail [options
] [files
]
Print the last few lines of one or morefiles
(the “tail” 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
This option prints the lastn
bytes, or ifn
is followed byk
orm
, the lastn
kilobytes or megabytes,
respectively.
m
Prints the lastm
lines. The
default is 10.
Continuously display a file as it is actively written by
another process (“follow” the file). This is useful for watching
logfiles as the system runs.