Sunday 26 April 2015

How to Compress and Extract Directory or File using "tar" Command


1)
Compress a file using tar command:

anusree@anusree-Inspiron-5547:~$ tar -cvf /home/anusree/tar_file            /my_music.tar -C /home/anusree/ my_music.mp3

a)
-cvf               

 | | |
 | |+--------------------------->   use archive file or device ARCHIVE
 |+----------------------------->   verbosely list files processed
+------------------------------->   create a new archive

b)
/home/anusree/tar_file /my_music.tar  -------->   Name of the compressed output file

c)

-C /home/anusree   -------------------->   Base location of the file to be compressed

d)

my_music.mp3   ----------------->  Name of the file to be compressed.

e)

There is a space between "-C /home/anusree" and "my_music.mp3"

2)

Extract a compressed .tar file using tar command

anusree@anusree-Inspiron-5547:~/tar_file$ tar -xvf my_music.tar my_music.mp3

3)

How to compress a directory of file in the current directory and save compressed file in current directory

$ tar -cvf output_file.tar my_directory


output_file.tar -->  Name of the compressed output file

my_directory   --> Name of the directory or file to be compressed





No comments:

Post a Comment