Monday, June 21, 2010

To Compress Drectory/File in Linux

To Compress Drectory/File in Linux.

Here we are going compress the directory/file using the tar command.
This is a good way to create backups and archives.

Some of the options used with the tar are: 

-c:  Create archive
-v:  Verbose i.e show the progress of the files being archived.
-f:  Archive File name
-t:  Show the list of files in the tar file.
-x:  Extract files from an archive.
-z:  Compress the tar file with gzip(gzip-Compression Tool)
-j:  Compress the tar file with bzip2(bzip-Compression Tool)


Example:

1)To compress the /home/admin/user1 folder as backup1.tar.gz

# tar -zcvf backup1.tar.gz  /home/admin/user1

To restore the 'tar.gz',

# tar -zxvf backup1.tar.gz

to restore in a particular directory

# tar-zxvf backup1.tar.gz -C /tmp


2)To compress the /home/admin/user1 folder as backup1.tar.bzip2

# tar -jcvf backup1.tar.bzip2  /home/admin/user1

To restore the 'tar.bzip2',

# tar -jxvf backup1.tar.bzip2






.

No comments:

Post a Comment