Sunday, February 6, 2011

Tutorial on Usage of Tar utility in Ubuntu/Debian/Mandriva/Fedora/OpenSuse Linux

A linux power user must know about the file compression utility tar. tar is used to store and extract files from and to an archive file. Mainly source codes distributed in tar format. Here some examples of tar usage

Create ( Archive) a tar file from a set of files :

tar -cvf tarfile.tar /var/log/samba /var/log/messages

Create a gzip file from a set of files (.tar.gz file):

tar -cvzf file.tar.gz /var/log/samba /var/log/messages

create bzip2 file from a set of files (.tar.bz2 file):

tar -cvjf file.tar.bz2 /var/log/samba /var/log/messages

Display the content of an ordinary tar file:

tar -tvf filename.tar
tar -tvzf filename.tar.gz
tar -tvjf filename.tar.bz2

Extract an ordinary tar file:

tar -xvf filename.tar
tar -xvzf filename.tar.gz
tar -xvjf filename.tar.bz2

Replace a file in an existing tar file:

tar -rvf tarfile.tar filetoreplace

Update a file in an existing tar file:

tar -uvf tarfile.tar newfile