
The program less got its name from the the precept that less is more and can also be
used to view the output of commands in a convenient way. To see how this works, read
Section “Redirection and Pipes”
(page 341).
Redirection and Pipes
Normally, the standard output in the shell is your screen or the console window and
the standard input is the keyboard. However, the shell provides functions by which you
can redirect the input or the output to another object, such as a file or another command.
With the help of the symbols
>
and
<
, for example, you can forward the output of a
command to a file (output redirection) or use a file as input for a command (input
redirection). For example, if you want to write the output of a command such as
ls
to
a file, enter
ls -l > file.txt
. This creates a file named
file.txt
that contains
the list of contents of your current directory as generated by the
ls
command. However,
if a file named
file.txt
already exists, this command overwrites the existing file.
To prevent this, use
>>
. Entering
ls -l >> file.txt
simply appends the output
of the
ls
command to an already existing file named
file.txt
. If the file does not
exist, it is created.
Sometimes it is also useful to use a file as the input for a command. For example, with
the
tr
command, you can replace characters redirected from a file and write the result
to the standard output, your screen. Suppose you want to replace all characters
t
of
your
file.txt
from the example above with
x
and print this to your screen. Do so
by entering
tr t x < file.txt
.
Just like the standard output, the standard error output is sent to the console. To redirect
the standard error output to a file named
errors
, append
2> errors
to the corre-
sponding command. Both standard output and standard error are saved to one file named
alloutput
if you append
>& alloutput
.
Using pipelines or pipes is also a sort redirection, although the use of the pipe is not
constrained to files. With a pipe (
|
), you can combine several commands, using the
output of one command as input for the next command. For example, to view the contents
or your current directory in
less
, enter
ls | less
. This only makes sense if the
normal output with
ls
would be too lengthy. For instance, if you view the contents of
the
dev
directory with
ls /dev
, you only see a small portion in the window. View
the entire list with
ls /dev | less
.
Working with the Shell
341
Содержание LINUX ENTERPRISE SERVER 10 - INSTALLATION AND ADMINISTRATION 11-05-2007
Страница 1: ...SUSE Linux Enterprise Server www novell com 10 May 11 2007 Installation and Administration...
Страница 14: ......
Страница 19: ...Part I Deployment...
Страница 20: ......
Страница 60: ......
Страница 128: ......
Страница 243: ...Part II Administration...
Страница 244: ......
Страница 274: ......
Страница 312: ......
Страница 348: ......
Страница 380: ......
Страница 381: ...Part III System...
Страница 382: ......
Страница 438: ......
Страница 452: ......
Страница 478: ......
Страница 486: ......
Страница 498: ......
Страница 512: ......
Страница 558: ......
Страница 559: ...Part IV Services...
Страница 560: ......
Страница 652: ......
Страница 670: ......
Страница 742: ......
Страница 754: ......
Страница 796: ......
Страница 817: ...Part V Security...
Страница 818: ......
Страница 858: ......
Страница 886: ......
Страница 910: ......
Страница 911: ...Part VI Troubleshooting...
Страница 912: ......
Страница 924: ......