Tar Command Use In Linux

Tar Command Use In Linux

Tar command is used to create maintain or modified and extract file which are archive in the tar format [$ tar (option)

{Option}

-c = creating an archive

-x = extract the archive

-v = display the verbose

-f = allow you specific the file name

-z = zip,tell tar command that create tar file using bzip

# sudo tar –cvf irfan.tar /jackx.data

the above command will create a tar archive file “irfan.tar” for a directory “jack.data” in current working directory

use only selected data test.txt and text.text

# sudo tar –cvf irfan.tar test.txt text.txt

The above command will create a tar archive file “irfan.tar” containing “test.txt” and “text.txt”

in current working directoryls

example

Extracting files from archive using option -xvf

$ sudo tar –xvf irfan.tar * press enter

Show the how many file in your irfan.tar we enter the command on our display see the example

$ sudo tar –xvf irfan.tar

Example

gzip command in linux

gzip is a compress tool which is used in linux

this command compresses more than the (–xvf) and save the file name (.tar.gz)

# sudo tar –cvz * press enter
$ sudo tar –cvzf test.tar.gz test.txt text.txt

Example

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. The following example command will create a (test.tar.bz2) file for a directory(test)

# tar cvfj test.tar.bz2 test * press enter
$ tar cvfj test.tar.bz2test

Example

Check the size of the tar archive file

To check the size of any tar  archive file, use the following command. For example the below command will display the size of archive file in Kilobytes (KB).

#tar –czf – irfan.tar | wc –c * press enter
$tar –czf –irfan.tar | wc –c

Example

Add file or directory in your tar archive file

To add files or directories to existing tar archived file we use the option r (append).

# tar –rvf irfan.tar vim * press enter
$ tar –rvf irfan.tar vim

Example

Same command use for (.tar.gz) and (.tar.bz2)

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest Comments

No comments to show.