Linux tar Command

The Linux tar command is used to compress and extract files to and from an archive. In this article, we’ll show the basic usage of the tar command. It is very handy when it comes to making full back ups of your files and folders or restoring your transferred website from another host.

Creating an Archive using the Linux tar command

tar -czvf file1 file2 file3 archiveToCreate.tar.gz

This will create an archive called archiveToCreate.tar.gz with the files file1, file2 and file3 in it.

The flags represent:

c – create
z – using gzip compression
v – verbal, displaying information about the archive while archiving
f – using an archive file

cPanel Hosting from WebhostFace

Creating an Archive of an Entire Directory

tar -czvf /path/to/directory/* archiveToCreate.tar.gz

You can use WildCard to create an archive of all files within a directory

Extracting an Archive using the Linux tar command

tar -xzvf archiveToExtract.tar.gz

This will extract all files in the archive in the current directory, the only flag that is changed is the -c (for creating) with the

x – extract the archive

Master your Linux knowledge and test your SSH skills using our cheap cPanel hosting packages, SSD VPS plans or Linux Dedicated servers. Now with great discounts up to 40% OFF the regular price!