Archive and Compress Files or Directories

Archive n Compress Files (Tar n Zip Command)

An Archive file is a file that is composed of one or more files along with metadata. Archive files are used to collect multiple data files together into a single file for easier portability and storage, or simply to compress files to use less storage space. 

  1. Tar: In Linux ‘tar’ stands for tape archive. Tar command is used to create Archive and extract the Archive files. We can use Linux tar command to create compressed or uncompressed Archive files and also maintain and modify them.

To archive two or more files :

tar –cvf tarfile.tar file1 file2

Here tarfile.tar is the archive file to be created after archiving file1 and file2 file.

in this case, we used three different options :

-c : for create archive, a pretty self-explanatory option if you want to create a new archive made from the files selected;-v : for verbose, this is the reason why the command displays the files added to the archive when executing it;

-f : for file, this option is used in order to specify the filename of the archive we want to create (in this case archive.tar)

To unarchive an archive file.

tar –xvf tarfile.tar

  1. zip, unzip— Use zip to compress files into a zip archive, and unzip to extract files from a zip archive.

The gzip utility can take a file, such as somefile.tar and compress it to make the file size smaller. Gunzip is the opposite of gzip and it uncompresses a file, returning it to its original.

$ gzip archive.tar

To unzip the file we can use

$ gunzip archive.tar.gz

If Gzip isn’t install on your system you can install it using

$ sudo yum install gzip
 

Leave Comment

Your email address will not be published.