Uses of Tar Command in Unix and Linux Server :
For archiving purposes on the Unix platform, tar command is command to be used. Knowing the various tar command options will help you to be a master of the archive file manipulation.
A. Create an archive with tar command
* Create an uncompressed tar archive with option cvf
It is the most basic command to create a tar archive.
$ tar cvf archive_name.tar dirname/
Note :
c – create a new archive
v – verbosely list files which are processed.
f – following is the archive file name
* Create a tar gzipped archive with option cvzf
The above used tar cvf, can’t offer any compression. So, if you want to utilize a gzip compression on the tar archive then you can utilize the z option as follows.
$ tar cvzf archive_name.tar.gz dirname/
Note :
z – filter the archive through gzip
Note:
.tgz is similar as .tar.gz
* Create a bzipped tar archive with option cvjf
Create a bzip2 tar archive as shown below:
$ tar cvfj archive_name.tar.bz2 dirname/
Note :
j – filter the archive through bzip2
Note:
.tbz and .tb2 is similar as .tar.bz2
B. Extracting (untar) an archive with tar command
* Extract a *.tar file with option xvf
Extract a tar file with option x as shown below:
$ tar xvf archive_name.tar
Note :
x – extract files from archive
* Extract a gzipped tar archive ( *.tar.gz ) with option xvzf
Use the option z for uncompressing a gzip tar archive.
$ tar xvfz archive_name.tar.gz
* Extract a bzipped tar archive ( *.tar.bz2 ) with option xvjf
Use the option j for uncompressing a bzip2 tar archive.
$ tar xvfj archive_name.tar.bz2
C. Listing an archive with tar command
* View the tar archive file content without extracting with option tvf
You can find out the *.tar file content before extracting as shown below.
$ tar tvf archive_name.tar
* View the *.tar.gz file content without extracting with option tvzf
You can find out the *.tar.gz file content before extracting as shown below.
$ tar tvfz archive_name.tar.gz read more