How to Tar and Untar a file in Linux?

I know there are many ways of doing it, however the below one is best as per me:

To create a compressed file:

1st way: If you would like to compress the whole folder, go to the folder and run the below command

tar cf – * | gzip > FIle_Name.tar.gz

2nd way: And if you would like to compress the folder from outside of the folder:

tar cf – folder_name | gzip > folder_name.tar.gz

To explode the file:

For 1st way:

Create a desired directory.

cd <directory_name>

gunzip < folder_name.tar.gz | tar xf –

For 2nd way:

And if you have created the .tar.gz file using the second way above go to any where run the below command it will create the directory automatically.

gunzip < folder_name.tar.gz | tar xf –

Hope it helps…

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