Archiving with tar

Creating tar file

compress

adding file to existing tar

update changes to previously compressed directory

extract and list tar contents

Create:

For Folder

[ahmad@SabryCentos01 /]$ sudo tar -cvf /home/hamada/etc.tar /etc

[ahmad@SabryCentos01 hamada]$ sudo tar -cvf etc.tar /etc/

[ahmad@SabryCentos01 hamada]$ sudo gzip etc.tar

For Files is the same:

[ahmad@SabryCentos01 ~]$ sudo tar -cjvf /home/magic/locale.conf.tar.gz locale.conf

Or

[ahmad@SabryCentos01 ~]$ sudo tar -cjvf /home/magic/locale.conf.tar.bz2 locale.conf

locale.conf

Use compression(gzip or bzip2):

While using tar you can add:

-z (gzip) or -j (bzip2) to compress

-> Zip while compresing:

[ahmad@SabryCentos01 hamada]$ sudo tar -cvjf /home/hamada/etc.tar.bz2 /etc/

Watch out the sequence of j before f

-> Zip after compressing:

Before:

[ahmad@SabryCentos01 hamada]$ gzip etc.tar

After:

Decompress(gunzip and bunzip2):

Using tar:

sudo tar -xvf etc.tar.gz

Using gunzip

[ahmad@SabryCentos01 magic]$ gunzip etc.tar.gz

Add:

tar cvf system-release.tar system-release

Then adding:

Update:

So The alternatives.tar is made from alternatives directory and has above files beneath.

Now moving ntp directory to the directory alternatives:

[ahmad@SabryCentos01 ~]$ mv ntp alternatives

Now updating the existing tar file with new changes:

[ahmad@SabryCentos01 ~]$ tar uvf alternatives.tar alternatives

Listing again the contents:

[ahmad@SabryCentos01 ~]$ tar tvf alternatives.tar

Extract:

All

Single file

Same directory

[ahmad@SabryCentos01 hamada]$ sudo tar xvf etc.tar.bz2 etc/exports

Different directory

[ahmad@SabryCentos01 hamada]$ sudo tar xvf etc.tar.gz -C /home/ahmad/tamam/ etc/hosts.ori

etc/hosts.ori

OR all contents:

[ahmad@SabryCentos01 etc]$ sudo tar xvf etc.tar.gz -C /home/ahmad/cervantes/

List Contents:

[ahmad@SabryCentos01 hamada]$ tar tvf etc.tar.gz |more

Advertisements

About Ahmad Sabry ElGendi

https://www.linkedin.com/pub/ahmad-elgendi/94/223/559
This entry was posted in Uncategorized. Bookmark the permalink.

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