Table of Contents
Compress Entire Directory to tar archive
Jul 2017
tar files are compressed files that contain all files and folders from a given location. The advantage to using .tar files, other than the obvious (potential) space saving is that you can include all file/folder permissions in the .tar file that would potentially be lost if you were doing a straight copy.
Create .tar File
The basic syntax for tar is quite simple, here is an example:
tar -switches xxx.tar.gz ABC
There are many switches available for .tar, but the main ones we will be using are:
p == preserve permissions c == create archive v == verbose (print names while making tar) z == gzip f == tar file name
To create a .tar archive, where the file name is archive.tar and the target folder is /home/work we would use the following syntax.
tar -pcvzf archive.tar /home/work
Decompress .tar File
To decompress the .tar file, we use the same tar command, we must use the same switches if we wish to preserve the file/folder structure and the file/folder permissions (permissions are very important).
To decompress the archive.tar file we created earlier, use the following command:
tar -pcvzf archive.tar