How to compress and extract the tar.gz files

You can compress a file or a folder with tar command. Its good to know that, file.tar.gz is the same with file.tgz.

 
 

File compression using tar command:

 tar -cvzf <name of tarball>.tgz /your file or folder directory

 

For instance to compress a file or folder you should type:

Tar -cvzf folder.tgz /home/user/folder

 Or

Tar -cvzf file.tgz /home/user/folder/file.txt

 Notice:

You can use tar cvzf instead tar -cvzf as well.

 
 

File Decompressing using tar:

To decompress or extract them, use the following command.

 
 

tar -xvzf file.tgz

or 

tar -xvzf file.tar.gz

 
 

There is no priority using the flags.

 -z: Compress archive using gzip program

-c: Create archive (compress)

-v: Verbose i.e display progress while creating archive

-f: Archive File name

-x :extract

Advertisements

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