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
Like this Article? Subscribe to Our Feed!
This article was posted on Sunday, April 29, 2012 at 7:55 PM