UnixServerAdmin

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

Advertisements

April 5, 2011 - Posted by | Tips & Tricks, Unix/Linux | , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: