| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Why do you need an archive? Archives/compressed archives are useful for taking backups and distributing files over the Internet.
In this chapter we will see how to create and extract an archive and a compressed archive.
15.1 Creating Archives 15.3 Extracting Files from Archives 15.8 More on Archives
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
tar
command from a terminal emulator as in these examples:tar -cvf <archive_name.tar> <file> [file...]tar -cvf flints.tar barney.txt fred.txt betty.txt
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
tar with the 'z' option compresses the files with gzip and creates a compressed archive (or tarball);
this is probably the most common use for tar. For example:tar -czvf flints.tgz barney.txt fred.txt betty.txttar -czvf rubble/
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
tar -xvf <archive_name.tar> [filename.tar...]
For example to extract all the files of the archive `flints.tar'
(created in the previous section)
tar -xvf flints.tar
This will extract the files `fred.txt barney.txt betty.txt'
To extract only `fred.txt'
`tar -xvf flints.tar fred.txt'
This will extract the files `fred.txt'
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
tar -zxvf flints.tgz
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
tar -tf <file.tar.gz>
For example to view the members of the archive `flints.tar'
tar -tf flints.tar
This will show you the following
fred.txt
barney.txt
betty.txt
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
.gz. Though there are other
file compressing utilities like compress, files compressed using
gzip are most common.
The command gzip <file> compresses the file. For example if I have
two files `/home/crypto/temp/foo.txt' and
`/home/crypto/temp/bar.txt'. Here is how to compress them
gzip /home/crypto/temp/foo.txt /home/crypto/temp/bar.txt
If you
are in the directory `/home/crypto/temp/' you do not have to
specify the full path to the file.
The files are replaced with one with the extension .gz. For
example, fter running the above example you will find `bar.txt.gz,
foo.txt.gz' innstead of `bat.txt' and `foo.txt'.
Gzip takes following command line options (among other)
-v
-h
You might have noticed that gzip does not lump the files together. Each
file is compressed separately. What if you want all your files in one
single archive? Just use the 'z' option
with tar as mentioned earlier.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
unzip filename.zip. For example, assuming I have
a file named `betty.zip' into my home directory. I'd use this to unzip it:unzip betty.zipzip filename file1 file2 file3 etc.. For example, if I wanted to create
a zip archive named `rock.zip' that contained the files `dino.txt bambam.txt wilma.txt', I'd do this:zip rock dino.txt bambam.txt wilma.txtzip myzip myfiles/*
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
info pages for tar comes with a tutorial which teaches
the even most intricate details in an easy to follow manner.(see section 8.2 Info Pages to learn howto use Info)
info page for gzip is also good to learn more.
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |