Novell LINUX ENTERPRISE DESKTOP 10 SP2 - DEPLOYMENT GUIDE 08-05-2008 Deployment Manual page 377

Table of Contents

Advertisement

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.
15.1.5 Archives and Data Compression
Now that you have already created a number of files and directories, consider the subject
of archives and data compression. Suppose you want to have the entire test directory
packed in one file that you can save on a USB stick as a backup copy or send by e-mail.
To do so, use the command tar (for tape archiver). With tar --help, view all the
options for the tar command. The most important of these options are explained here:
-c
(for create) Create a new archive.
Working with the Shell
361

Advertisement

Table of Contents
loading

This manual is also suitable for:

Linux enterprise desktop 10 sp2

Table of Contents