Tutorial: Using tar command to Archiving/Unarchiving files

                         

This tutorial shows you how to use tar utility to Archiving/Unarchiving your files on linux/unix machine.

Introduction
tar command is very good tool for archiving and unarchiving files. The "tar" command stands for tape archive. The tar command can be used to write archives directly to tape devices, or you can use it to create archive files on disk. In many cases, tar archives are created on disk so it's easier to transport them across networks, such as the Internet.

The basic command for archiving files with the tar command is:

tar -cvf archive.tar file1 file2

or

tar -cvf archive.tar file1 file2  (for archiving everything in the directory) where: c - for creating a new file
  • v - displays the name of each file being archived
  • f -  for using the files name for achieving
  • file1, file2, ... are the names of files that are being archived

Archiving Directory

-C option is used to archive the directory using tar command. For example you want to archieve a called "mydir", so you will be using the following command:

tar -cvf archive.tar -C mydir

Unarchiving using tar command

You can use tar utility to unarchieve your tar files. Suppose you have a tar file called "myfile.tar" and you want to unarchieve it. Then the following command you will be using to unarchieve the file:

tar -xvf myfile.tar