Server Administration & Management

How to create archives and compress file in Linux

With Linux default environment, tar is come by default and you may easily archives and compress a file or folder easily by using tar command. If you familiar with Linux, you should know that file could be archives to .tar, .tar.gz, .tgz, .bz2, .tgz, etc, but do you know how to archives it and how to remember and understand it? It is pretty easy, actually. To archives each of the folder/file, you may refer to the step as below.

.tar –> tar -cf file.tar folder/  [c indicate that you are creating a file and f is use to force create the inheritance file from the folder]

.tar.gz –> tar -zcf file.tar.gz folder/  [ z indicate that you are using .tar.gz or tgz extension]

.tgz –> tar -zcf file.tgz folder/

.bz2 –> tar -jcf file.bz2 folder/  [ bz2 is a type of archives that using lesser space and it required option j]

.gz –> gzip file.gz folder/  [gzip use to zip and remove the original file]

.zip –> zip -r folder.zip folder/  [zip is another archives type that not using tar but it is useful for Windows Operating System]

To extract the file as above, simply change all c to x.

.tar -> tar -xf file.tar

.tar.gz -> tar -zxf file.tar.gz

.tgz -> tar -zxf file.tgz

.bz2 -> tar -jxf file.bz2

.gz -> gunzip file.gz

.zip -> unzip folder.zip

April 5, 2011 Posted by | Tips & Tricks, Unix/Linux | , , | Leave a comment

How to create a tar archive from a directory

How can you do this? It’s not difficult at all. For exemple to backup a user home directory you would have to run:

# tar -pczf rchive.tar.gz /home/USERNAME

Since I started working with cPanel server I always needed to create archives from directories.
For example backing up a user’s home directory.

You can read more about tar by reading it’s manual.

# man tar

January 31, 2011 Posted by | Tips & Tricks, Unix/Linux | , , , , | Leave a comment