File or data compression is a technique used in reducing file size in order to take about 40% of it actual size on the hard drive. This is very important because most data are too big so transferring it on a network will take a lot of time. Most Web servers like Google uses this technique to be able to store a lot of data in a little space on there cloud storage.Well you might not have a cloud server but you may have a file on your mobile phone or Linux system that is taking a lot of space that you like to compress and still keep it your system.
Let's look at a scenario where you have a couple of backup files on your system
that is taking a lot of space , Then Linux have something for you on that. Let's drive right into it.
There are two main types of of compression
lossy
Lossy compression reduces your file size by chopping off bits and pieces that aren't 100% necessary to function. A better examples of files on your system that is currently on this type of compression are video files, musics Wow yeah you will say you haven't noticed it right? because the compression engine used for it will make It in a way that it will still be possible for the sound quality reduction won't be notice by you.
lossless
Lossless compression takes your files and reduces their size without losing any information. Most word and database documents use this type of compression technique.
So let's talk about three Linux popular compression and archiving utility.
gzip
DESCRIPTION
Gzip reduces the size of the named files
using Lempel-Ziv coding (LZ77).
Whenever possible, each file is replaced
by one with the extension .gz, while
keeping the same ownership modes, access
and modification times.
$ gzip filename
When you use the ls command you will see that the filename is now saved as filename.gz .
$ gzip -k filename
Adding the -k option will make it to keep the older file.
$ gunzip filename.gz
To unzip the any file that has .gz extentions.
$ zcat filename.gz
To view the content of a gz file without decompressing it .
bzip2
DESCRIPTION
bzip2 compresses files using the
Burrows-Wheeler block sorting text
compression algorithm, and Huffman
coding. Compression is generally
considerably better than that achieved
by more conventional LZ77/LZ78-based
compressors, and approaches the
performance of the PPM family of
statistical compressors . it uses an algorithm that achieves higher level of compression at the cost of compression speed.
$ bzip2 filename
This will compress filename using the bzip2 standard , so if you use the ls command you will that filename is saved as. filename.bz2
$ bzip2 -k filename
This make bzip2 to compress and still keep the original file.
$ bzcat filename.bz2
This will display the contents of a bzip2 file without decompressing it.
$ bunzip2 filename.bz2
To uncompress any bzip2
tar for tape archive
DESCRIPTION
GNU tar is an archiving program designed
to store multiple files in a single file
(an archive), and to manipulate such
archives. The archive can be either a
regular file or a device (e.g. a tape
drive, hence the name of the program,
which stands for tape archiver), which
can be located either on the local or on
a remote machine. Tar format
$ tar -cvf (Archive.tar .tar) (Directoryname.tar)
Archive.tar : is the name that the archive will bear after tar has performed archive.
Directoryname : Is the name of the folder/directory to be archived.
$ tar -cvf Archive.tar backup
The c in the option will create an archive of backup directory then v will make it display the current state of the directory archive and f will help to force the directory to create archive.
$ tar -xvf Archivename.tar
This will extract an archived directory
$ tar -tf Archivename.tar
To view content of Archivename.tar
Wow we have gone a long way today there are lots of other compression utility for Linux operating system other than the ones I covered here, you can also check out the man pages for the commands to know more about them. let me know what you think on the comment down below
Comments
Post a Comment