Suse LINUX Professional 9.3 Update 00662644461625 User Manual

Product codes
00662644461625
Page of 304
19
W
or
king
with
the
Shell
and standard error are saved to one file named
alloutput
if you append
>&
alloutput
. Finally, to append the output of a command to an already existing
file, the command must be followed by
>>
instead of a single
>
.
19.1.8
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 floppy disk 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.
-t
(for table) Display the contents of an archive.
-x
(for extract) Unpack the archive.
-v
(for verbose) Show all files on screen while creating the archive.
-f
(for file) Choose a filename for the archive file. When creating an archive,
this option must always be given as the last one.
To pack the
test
directory with all its files and subdirectories into an archive
named
testarchive.tar
, use the options
-c
and
-f
. For testing purposes,
also add
-v
to follow the progress of the archiving, although this option is not
mandatory. After using
cd
to change to your home directory where the
test
di-
rectory is located, enter
tar -cvf testarchive.tar test
. After that, view
the contents of the archive file with
tar -tf testarchive.tar
. The
test
directory with all its files and directories has remained unchanged on your hard
disk. To unpack the archive, enter
tar -xvf testarchive.tar
, but do not
try this yet.
For file compression, the obvious choice on Linux is the popular gzip pro-
gram. Just enter
gzip testarchive.tar
. With
ls
, now see that the file
testarchive.tar
is no longer there and that the file
testarchive.tar.gz
has been created instead. This file is much smaller and therefore much better
suited for transfer via e-mail or storage on a floppy.
Now, unpack this file in the
test2
directory created earlier. To do so, en-
ter
cp testarchive.tar.gz test2
to copy the file to that directory.
253
SUSE LINUX