A Brief introduction to file compression
File compression is a routine task for most of the Administrators and normal users, to save disk space and to move data from one location to another safer location, this compression utility is used. from historical point of view tar utility was developed to get sequential data backup and it was stored in magnetic tape drives. To send data via internet the compression utility play an important role, it can hold multiple files together and will reduce the overall file size, this can save both the time and internet bandwidth, Linux comes with very quick and effective tools which can reduce file sizes from 40 to 80 percent. In this article we will discuss top 15 utilities in Linux available for users.
Although maximum of the data compression tools are available with all flavors of Linux, but we will be using Mint 17 Linux for demonstration purpose, some of the tools are command line based and some of them are with GUI, let us discuss them one by one.
tar file compression
The word tar is extracted from tape archive, this is most popular compression and decompression tool for Linux administrators, it is used to archive in multiple file formats like gzip, bzip2 or lzip etc.
Install tar in Debian/Ubuntu
# apt-get install tar
Install tar in CentOS
# yum install tar
First argument with tar command must be anyone from Acdrtux.
Crate a file of 512MB size
# fallocate -l 512M um.img
# tar -cvfz um.tar.gz um.img
-c– to create archive, -v – verbose, -f for archiving file, -z to compress files in gzip format.
Use man utility for more details.
2. gzip file compression
The gzip tool is most popular and fast file compression utility in Linux. Gzip tool keep original file name the extension of compressed file .gz and time stamp. Usually comes as inbuilt package for all distributions but can be install easily.
# apt-get install gzip
# yum install gzip
# gzip examplefile
To get details about compressed file
# gzip -l examplefile.gz compressed uncompressed ratio uncompressed_name 203559 209715200 99.9% examplefile
To unzip compressed file
#gzip -d examplefile.gz
To compress all file and directories recursively
# gzip -r examplefile
The above utility is not recommended to use, otherwise it can create complications while recovering the data.
3. lzma file compression
Lzma is compression tool like zip or tar, but it perform quick in comparison to bzip, comes as builtin for all Linux distributions.
To create a archive, use following command
# lzma -c --stdout examplefile> examplefile.lzma
To extract data
# lzma -d --stdout examplefile.lzma >examplefile
Although lzma is a strong tool but it is not so popular among Linux users.
4. xz file compression
XZ is successor of the lzma utility, it can only compress single file but can not compress multiple file in a single command. This utility was introduced in 2009 so there is a possibility that it can not be supported on older Linux versions, but it is provided with all of the latest Linux operating systems, it will addd .xz extension to compression file automatically.
To compress a file
# xz examplefile
To decompress a file
# xz -d examplefile.xz
5. bzip2 file compression
Bzip2 utility perform more faster then gzip, it compress files and folders more compactly. It required more RAM during compressing files, to reduce memory consumption, pass -s flag in option.
# bzip2 examplefile
Pass -s flag
# bzip2 -s examplefile
To decompress the .bz2 compressed file
# bzip2 -d examplefile.bz2
# bunzip2 examplefile.bz2
Use -v option to verbose
# bzip2 -v examplefile examplefile: 1184831.638:1, 0.000 bits/byte, 100.00% saved, 209715200 in, 177 out.
6. pax file compression
Pax is less know archiving tool in Linux, it perform fast and is it is more than just a compressor, it can real archive it can copy files remotely, pax is not installed by default in Ubuntu/Mint Linux.
# apt-get install pax
# pax -wf examplefile.tar examplefile
woption to write archive, f for file.
To compress file in bzip or gzip use -z option
# pax -wf examplefile.tar.gz examplefile
List content of archive
# pax -f examplefile.tar
Extract contents of archive
# pax -r <examplefile.tar
7. Peazip file compressor
Peazip is a cross platform compression utility, it is based upon open source utilities like 7zip, p7zip, freearch etc, it supports more then 180 file formats. A good alternative to WinRar.
Download package and install
# wget sourceforge.net/projects/peazip/files/5.3.1/peazip_5.3.1.LINUX.Qt-2_i386.deb
# dpkg -i peazip_5.3.1.LINUX.Qt-2_i386.deb
8. 7zip file compressor
7Zip file compressor is an open source utility which was developed originally for Microsoft Windows, it supports multiple file compression formats and known for high file compression, it can be used for compressing multiple files with a single command.
# apt-get install p7zip-full p7zip-rar
# 7z a examplefile.7z examplefile
To extract file
# 7z e examplefile.7z
9. shar file compression
Shar is a command line utility which can be used to compress test files, shar can be defined as “shell archive”. A simple and quick file archiving utility can be useful to get archive of shell scripts.
# apt-get install sharutils
# shar examplefile > examplefile.shar
# unshar examplefile.shar
10. cpio file compression
Can be defined as copy input and output, it read a list of file name line by line in input and archive files in output. Its a classic command and comes as built in.
# cd /tmp
ls | cpio -ov >/home/username/backup.cpio
# cpio -idv <backup.cpio
The ancestor or predecessor of rar, still used in Debian and its derivatives, a simple archiving tools but it is not so popular command.
# ar cvsr examplefile.a examplefile
# ar -xv examplefile.a
Used to get a virtual disc image or .iso image of optical drive which can be used later to burn a new disk or as some installation media for hyper version based virtualization, a very useful tool of Linux Administrators as optical drives got corrupt often therefor it is a good method to get backup of your server of software optical disc which can be utilized later.
# dd if=/media/dvd of=/home/username/filename.iso
Kgb is a less known but effective archiving tool that is capable of compressing multiple file into a small high compression ration archive. It supports all of the common file archive formats like zip, gzip, 7zip and rar.
# apt-get install kgb
# kgb examplefile.kgb examplefile
# kgb x examplefile.kgb
Capable to handle large files, lightweight and it was Written by Matt Mahoney in Jun 16 2010, it propose high standard data compression archive, it is based upon PAQ context mixing algorithms.
# apt-get install zpac
# zpaq c examplefile.tar examplefile
15. File Roller
File roller is archive manger in GUI for Linux, it can create or modify archives, it can show the contents of archive,a good alternative to 7zip or winrar. supports almost all of the file formats like .iso, .lsa, 7zip, gzip, zip, zz etc. comes a built in under Mint and Ubuntu distro.
The performance of compression utility may differ system to system depending upon the size of the file and the processing speed of the system, it is always recommended to get gradual data backups which should be save to some separate hard disk or another data storage device. Although a lots of data compression tools are available but you should use standard and time tested tools only.