How To Manage Archives With Tar and Untar

back to tech articles
CentOS 6

This is not the most comprehensive guide, but rather a quick tip to tar and untar directories. Tar is a powerful file archive and compression utility that is fast to execute and creates conveniently small archives when used with compression turned on.

Archive

The syntax is very easy. Here’s how we create a basic, uncompressed tar archive:

1
2
3
4
5
$ tar -cvf archivename.tar directory/files_and_more_directories
OR
$ tar -cvf archivename.tar .
OR
$ tar -cvf archivename.tar ./*

The last two commands will archive everything in the current folder into the named tar archive. By default, this archive is not compressed (one of the features where tar really shines). We stipulate compression with the -z switch:

1
2
3
4
5
$ tar -czvf archivename.tar directory/files_and_more_directories
OR
$ tar -czvf archivename.tar .
OR
$ tar -czvf archivename.tar ./*

Extract

That’s it for creating the archive, now to extract it:

1
2
3
4
5
// an uncompressed archive
$ tar -xvf archivename.tar
OR
// a compressed archive
$ tar -xzvf archivename.tar

That’s all from me. Here is the man page for tar for a full description.

Leave a Reply

Your email address will not be published. Required fields are marked *