Search

How to use Linux tar (tape archive) command to create archives

The Linux tar (tape archive) command is used to convert a group of files into an archive.

An archive is a single file that contains any number of individual files plus information to allow them to be restored to their original form by one or more extraction programs.

To create a tar file from the contents of a folder, use the Linux tar command with the following options.

[[email protected] mytar]# tar cvf mytar.tar mytar/

After creating a tar file, it can be compressed to save the storage space, by using gzip or bzip2 command. The following command shows how to compress the tar file with bzip2 command.

[[email protected] mytar]# bzip2 -c mytar.tar > mytar.tar.bz2

To uncompress the bzip2 file, use the following command.

[[email protected] mytar]# bzip2 –d mytar.tar.bz2

To extract the tar file back to its original contents use the following options with the tar command.

[[email protected] mytar]# tar -xvf mytar.tar

Related Tutorials
• How to compress, uncompress and view files using Linux commands gzip, gunzip and zcat
• How to compress uncompress view files using Linux commands bzip2 bunzip2 and bzcat
• Introduction to RedHat Package Manager (RPM)
• Introduction to YUM (Yellow dog Updater, Modified) Package Manager