To create an archive of a directory tree with tar, you can do something like this:
The preceding command creates (c) the file (f) directory.tar, which is a tar archive, by running tar on directory. If you add the option v (for verbose), tar will print the name of each file as it adds it to the archive.
If you do this with a directory containing a couple of small text files, and then you look at the resulting tar file (with cat), you will see that it is just a concatenation of the original files themselves together with additional information.
If you want to list the files in the archive, use the t option:
[email protected]:~/temp> tar -tf directory.tar directory/
Here the t option lists the contents of the file (f) directory.tar. Using gzip Compression with tar
If you want to create a gzipped tar archive (the -z option implies compression, while the c means create):
The original is still there, unlike when we compressed a single file with gzip. (Note that .tgz and .tar.gz are used interchangeably for filenames of gzipped tar archives.)
To list the files in this case, use the following:
[email protected]:~/temp> tar -tzf directory.tgz directory/
Was this article helpful?