This command will archive a bunch of your files or directories.
user@box ~$ tar -cf foo.tar foo/
Once the archive is created, we can list the files and directories inside it using the following command.
user@box ~$ tar -tf foo.tar
We will now try to extract the contents of the archive into the '/tmp' directory. Since we had archived the entire 'foo' directory, extraction would lead to the creation of an identical 'foo' directory inside '/tmp'.
user@box ~$ tar -xf foo.tar -C /tmp
We can also compress the newly created archives and decompress them while viewing their contents or extracting. There are two algorithms for compressing and decompressing the archives-- Gzip and Bzip2.
If we are using the Gzip algorithm, the above three commands would become:
user@box ~$ tar -czf foo.tar.gz foo/ user@box ~$ tar -tzf foo.tar.gz user@box ~$ tar -xzf foo.tar.gz -C /tmp
If we are using the Bzip2 algorithm, then we would have used:
user@box ~$ tar -cjf foo.tar.bz2 foo/ user@box ~$ tar -tjf foo.tar.bz2 user@box ~$ tar -xjf foo.tar.bz2 -C /tmp
''tar' offers a large number of options. We have already seen how to use some of the most common of these. If you are interested to know more, then you may read the manual using the following commands:
user@box $~ info cd user@box $~ man cd