Tar is a program that archives files into a single package that you can move around easily. After using the tar command ,you are left with a single tar file which is referred to as a âtarballâ. A tarball is compressed ,but you can compress it further by adding the âzâ flag which gzips it into a smaller file. This is how I typically use tar:
tar cvzf mytarball.tgz .
The âcâ flag means âcreate a tarballâ, the âvâ flag stands for âverbose modeâ or âshow every file that is compressed as it happensâ, the âzâ flag means âgzip the tarball further (hence the .tgz extension instead of .tar)â and the âfâ flag means âuse the tarfile argument as the name of the tarfileâ. The argument âmytarball.tgzâ is the name of the file. You can name it whatever you like; the extension does not matter â I just like using .tgz. The last argument â.â means include all files in the current directory and all subdirectories. After running this command you now have a compressed âmytarball.tgzâ file. You can move this file around wherever you need it. If I needed to download an entire site via FTP I would run this command and then just download the single tarball rather than downloading many files individually.
The opposite of archiving is unarchiving (o rly?). To unarchive a gzipped tarball use the following:
tar xvzf mytarball.tgz
Itâs that simple. The flags are the same except you use âxâ instead of âcâ which means âextractâ. This will uncompress your tarball in the current directory you are in, maintaining the original directory hierarchy.