Novell LINUX ENTERPRISE SERVER 10 SP2 - INSTALLATION AND ADMINISTRATION Installation Manual page 377

Hide thumbs Also See for LINUX ENTERPRISE SERVER 10 SP2 - INSTALLATION AND ADMINISTRATION:
Table of Contents

Advertisement

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 359).
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
359

Advertisement

Table of Contents
loading

This manual is also suitable for:

Suse linux enterprise server 10 sp3

Table of Contents