Tar for Linux is essentially what zip is for Windows and Mac (though Linux can do zip as well). To compress files using tar, use the following syntax:
tar –czfv destinationfile.tar.gz file.or.directory.to.compress
Let’s break down the options really quickly:
-c Create the file you are compressing to
-z gzip the file as well to make it more compressed
-f forceful compression, include all subdirectories and files
-v verbose, list all files and directories as you compress them
Obviously –z and –v are not necessary. I always recommend –z just because if you are going to compress something, you might as well compress it as much as possible, especially if you are going to move it.
It takes a little longer to do this, but usually saves at least that amount of time on transfer time. The –v option will slow down the tar to show what is being compressed. If you are confident that the command is correct, you may want to consider omitting this option to speed it up. Unfortunately, there isn’t a good way to tell how far along the tar process is, or when it will finish, especially with the gzip option.
To uncompress a tar.gz file, simply replace the –c with a –x and skip the target directory:
Tar –xzfv compressedfile.tar.gz
The –xzf simply means extract using forceful recursion and gunzip it as well. The –v option, as always, means verbose. If the file is just a .tar file and not .tar.gz or .tgz then be sure to exclude the –z option. By default, uncompressing a tar archive will overwrite any existing files of the same name found in the location where you are uncompressing the file without asking.