TAR COMMAND IN UNIXLINUX

0
385

TAR COMMAND

TAR command stands for tape archive. It is an archiving file format. which is used by a large number of Linux/Unix system administrators to deal with tape drives backup. The tar command used to rip a collection of files and directories into highly compressed archive file commonly called tar, gzip and bzip in Linux. The tar is most widely used a command to create compressed archive files and that can be moved easily from one disk to anther disk or machine to machine.

The Syntax to create tar archive

tar -cvf archive.tar file1 file2

c – Creates a new .tar archive file.
v – Verbosely shows the .tar file progress.
f – File name type of the archive file

tar-command-example2

Create tar.gz Archive File To create a compressed gzip archive file we use the option as z
.tgz is same as .tar.gz

 tar -cvzf archive.tar.gz file1 file2

tar-example3

Create tar.bz2 Archive File

The bz2 feature compress and create archive file less than the size of the gzip. The bz2 compression takes more time to compress and decompress files as compared to gzip which takes less time. To create highly compressed tar file we use option as j.

tar -cvjf archive.tar.bz2 file1 file2

tar-example4

Untar tar Archive File

To untar or extract a tar file, just issue the following command using option x (extract)

tar -xvf archive.tar

tar -xvf archive.tar -c /home/admin

tar-example5

If you want to untar in a different directory then use option as -C

Uncompress tar.gz and tar.bz2 Archive File

To Uncompress tar.gz archive file, just run the following command. If would like to untar in different directory just use option -C and the path of the directory

tar -xvf archive.tar.gz

tar -xvf archive.tar.bz2 -c /home/admin 

tar-example6

List Content of tar Archive File

To list the content of tar archive file, just run the following command with option t

tar -tvf archive.tar

tar -tvf archive.tar.gz

tar -tvf archive.tar.bz2

Add Files or Directories to tar Archive File

To add files or directories to existing tar archived file we use the option r

tar -rvf archive.tar filename

tar -rvf archive.tar.gz filename

tar -rvf archive.tar.bz2 filename

Check the Size of the tar, tar.gz and tar.bz2 Archive File

To check the size of any tar, tar.gz and tar.bz2 archive file, use the following commands.

tar -czf - archive.tar | wc -c

tar -czf - archive.tar.gz | wc –C

tar -czf - archive.tar.bz2 | wc -c

Comments

comments