The archive format preserves the directory structure, and the file system attributes such as permissions and dates.
tar [function] [options] [paths]
The tar command supports the following functions:
While specifying the function, the ‘-‘ prefix is not required, and the function can be followed by other single letter options.
Some of the supported options include:
Create an archive file containing file1 and file2
$ tar cvf archive.tar file1 file2
Create an archive file containing the directory tree below dir
$ tar cvf archive.tar dir
List the contents of archive.tar
$ tar tvf archive.tar
Extract the contents of archive.tar to the current directory
$ tar xvf archive.tar
Create an archive file containing the directory tree below dir and compress it using gzip
$ tar czvf archive.tar.gz dir
Extract the contents of the gzipped archive file
$ tar xzvf archive.tar.gz
Extract only the given folder from the archive file
$ tar xvf archive.tar docs/work
Extract all “.doc” files from the archive
$ tar xvf archive.tar –-wildcards ‘*.doc’
The archive format of Tar Command in Unix preserves the directory structure, and the file system attributes such as permissions and dates.