How to Create and Extract a gzip Compressed Archive File on Linux

Related Articles

Archiving and compressing files are useful when creating backups and transferring data across a network. One of the oldest and most common commands for creating and working with the backup archives is tar command. tar originally stood for tape archiver. With tar, we cab gather large sets of the files into a single file(archive). We can indicate that the archive should be compressed using gzip or bzip2 compression.

To use tar command, one of the three following options is required.
c = create and archive
x = extract and archive or
t = test or list the contents of an archive

Other options let you add vebosity(v), indicate the name of the archive file to create or extract and set the type of compression to use (g for gzip or j or bzip2).

This example will show an examples of tar syntax which will create (c) a gzip compressed(z) archive file (f /tmp/etc.tar.gz) of the /etc directory. Be verbose(v) with the output. This command has been tested on Redhat Enterprise Linux 6 (RHEL6) with root access and it will backup entire /etc directory.

[root@rhel6 ~]# tar cvzf /tmp/etc.tar.gz /etc

Meanwhile, this tar command will show hpw to extract(x) and view(v) all files from a gzip-compressed(z) archive(f /tmp/etc.tar.gz) to the /backup-test directory.

Create /backup-test directory and cd to /backup-test.

[root@rhel6 /]# mkdir /backup-test
[root@rhel6 /]# cd /backup-test
[root@rhel6 backup-test]# pwd
/backup-test

Extract(x) and view(v) all files from a gzip-compressed(z) archive(f /tmp/etc.tar.gz) to the /backup-test directory.

[root@rhel6 backup-test]# tar xvzf /tmp/etc.tar.gz

List the extracted directory ;

[root@rhel6 backup-test]# ls
etc
Sign up for the WP Engine affiliate program and receive a minimum of $150 per referral!

As always if you need any help you can reach us on twitter @ehowstuff or drop us a comment below. Jumping through archives page to read more articles..


Skytech is a part time blogger that has over 6 years experience in servicing, repairing and configuring computers and administering the server systems.

Related Articles

Powered by WordPress · Designed by Theme Junkie