Linux File Compression And Archiving Tools

There are many utilities are available in Linux to compress and decompress files.

These tools save disk space by temporarily compressing unused files or directories.

It is useful to store a group of files in one file for easy backup, for transfer to another directory, or for transfer to another computer.

It is also useful to compress large files; compressed files take up less disk space and download faster via the Internet.

In this article, we are going to discuss about four common compress methods called zip, gzip, bzip2 and tar.

1) Zip And Unzip – Linux File Compression And Decompression Tool

zip and unzip is a compression and file packaging utility for Linux, Unix, Windows & Mac OS X.

Its useful for packaging/compressing a set of normal files, one or more compressed files into a single zip archive, along with information about the files (name, path, date, time of last modification, protection, and check information to verify file integrity) and stores in a single zip file.

This save disk space by temporarily compressing unused files or directories.

It will automatically uses the Zip64 extensions when files larger than 4 GB are added to an archive, or when the number of entries in the archive will exceed about 64K.

The unzip program used to unpacks zip archives. We can create a entire directory structure zip archive with a single command.

Compression ratios of 2:1 to 3:1 are common for text files.

Both utilities are available in all major Linux distribution by default but not installed.

You can install it by using the distribution official package manager.

Syntax:

Common syntax for zip and unzip command.

For zip (File compression)

# zip [FileName.zip] [Files To Be Compressed]

For zip (File decompression)

# zip -d [FileName.zip]

For unzip (File decompression)

# unzip [FileName.zip]

2) Gzip And Gunzip – Linux File Compression And Decompression Tool

gzip and gunzip is one of the compression method in Linux.

It compresses the normal file and stores into single .gz extension file, this compression is much better compared with zip compression.

Gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Gzip will only attempt to compress regular files. In particular, it will ignore symbolic links.

By default, gzip keeps the original file name and timestamp in the compressed file. These are used when decompressing the file with the -N option.

Compressed files can be restored to their original form using gzip -d or gunzip or zcat. If the original name saved in the compressed file is not suitable for its file system, a new name is constructed from the original one to make it legal.

Compression is always performed, even if the compressed file is slightly larger than the original.

Syntax:

Common syntax for zip and unzip command.

For gzip (File compression)

# gzip [Files To Be Compressed]

For gzip (File decompression)

# gzip -d [FileName.gz]

For gunzip (File decompression)

# gunzip [FileName.gz]

3) Bzip2 And Bunzip2 – Linux File Compression And Decompression Tool

bzip2 and bunzip2 is one of the compression method in Linux, high-quality data compressor.

It typically compresses files to within 10% to 15% of the best available techniques (the PPM family of statistical compressors).

It compresses the normal file and stores into single .bz2 extension file, this compression is much better compared with gzip compression.

bzip2 compresses files using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding.

The command-line options are deliberately very similar to those of GNU gzip, but they are not identical.

bzip2 expects a list of file names to accompany the command-line flags. Each file is replaced by a compressed version of itself, with the name “original_name.bz2”.

Each compressed file has the same modification date, permissions, and, when possible, ownership as the corresponding original, so that these properties can be correctly restored at decompression time.

Syntax:

Common syntax for bzip2 and bunzip2.

[bzip2 (Compress) syntax]
# bzip2 [Files To Be Compressed]

[bzip2 (Decompress) syntax]
# bunzip2 [FileName.bz2]

[bzip2 (Decompress) syntax]
# bzip2 -d [FileName.bz2]

[bzip2 (Decompress) syntax]
# bzcat -dc [FileName.bz2]

4) How To Use Tar Command Effectively In Linux For Backup

The Linux tar command stands for tap archive, is not a compressed file and commonly called as a collection (which contains the contents of many files) of a single file.

Tar is the most commonly used command in Linux for creating a archive file. It saves multiple files, folders & other file formats (zip, gzip, bzip2 & tar) into a single archive file. Many of us very frequently uses three operations create, list & extract & two options file & verbose with tar to dealing the backups and restore.

Additionally we can use gzip & bzip2 commands for further compressing the tar archive. Mainly tar command used to performing backup (full and incremental) from the server by server administrator, other famous backup applications are using tar command for backup.

All the files and folders can be restore from the archive file whenever you want, every server administrator need to know the tar command and it’s usage for better backup solution.

By default tar command included into most of the distribution, so we can easily install from distribution official repository.

Syntax:

Common syntax for bzip2 and bunzip2.

[tar (Compress) syntax]
# tar -cvf [FileName.tar] [Files/Folders To Be Compressed]

[tar.gz (Compress) syntax]
# tar -zcvf [FileName.tar.gz] [Files/Folders To Be Compressed]

[tar.bz2 (Compress) syntax]
# tar -jcvf [FileName.tar.bz2] [Files/Folders To Be Compressed]

[tar (Decompress) syntax]
# tar -xvf [FileName.tar]

[tar.gz (Decompress) syntax]
# tar -xzvf [FileName.tar.gz]

[tar.bz2 (Decompress) syntax]
# tar -xjvf [FileName.tar.bz2]

Linux File Compressing:

Command/Syntax Examples/Details
zip [FileName.zip] [Files To Be Compressed] zip file.zip magesh.txt
zip: Command
file.zip: zipped file name
magesh.txt: file to be compressed
gzip [Files To Be Compressed] gzip magesh.txt
gzip: Command
magesh.txt: file to be compressed
bzip2 [Files To Be Compressed] bzip2 magesh.txt
bzip2: Command
magesh.txt: file to be compressed
tar [Options] [FileName.tar] [Files To Be Compressed] tar -cvf backup.tar /home/magesh
tar: Command
-cvf: Options for tar archive
backup.tar: Archived File Name
/home/magesh: files/Folders to be compressed

tar -zcvf backup.tar.gz /home/magesh
-z: for gzip archive

tar -jcvf backup.tar.bz2 /home/magesh
-j: for bzip2 archive

Hope this article was useful for you. Kindly provide your valuable feedback/comments in the commenting section.

Stay tuned with us !!

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...