Why we Compress Files and the bzip2 Utility
You may frequently download compressed files from the internet. Have you wondered why the files you download are compressed?
Not everyone has the privilege to pay for a fast internet connection and not everyone can afford an external hard drive. Transferring files through slow internet connection is boring and time consuming. Can we find a solution for this? Yes we can! We always can! Do you send large documents via email? Do you compress your files before sending them to your boss? No? Ok, don’t do that anymore because this costs the recipient time, energy and money. Now it is time to learn how to compress files using the command-line. Don’t worry guys, it is not going to be hard, I promise.
The utility you will learn in this article compresses and decompresses files. After you have downloaded a compressed file from the internet you need to decompress it so you can use it.
The bzip2 Utility
The bzip2 tool compresses files and it works very well on text files. This utility analyses the files which is going to be compressed and records it more efficiently. You can say from the way it works that this utility works particular well on files that have repeated information such as image data and text data. How do I know if a files is compressed with the bzip2 utility or not? The bzip2 utility renames the files it compresses by adding the bz2 suffix. Note: The compressed file can not be displayed or used without being decompressed. Ok, now it is time to show you guys the bzip2 utility in action.
I have an image on my desktop and I want to compress it using the bzip2 utility. You can see from Figure 1 that the size of my image is 24K and it is in PNG format.
To compress my image I use ‘bzip2 -v file_name‘. The -v options stands for verbose and I use it because I want to know what is happening. The -v option gives you information about the input size, output size and the percentage of compression. You can see that in details by analysing Figure 2.
As you can see from Figure 2, the bzip2 utility can reduce the size of our files by 5.12%. If you are the curious type of guy you can calculate that manually and verify that the percentage is correct. I did. Now, you can see from Figure 3 that in place of the comparison.png file is comparison.png.bz2 file. Does bz2 tell anything to you? What information do you get from this suffix? Can you open the file by double clicking it like you did with the image file? Let me give a try. I will be back…
Guys I am back and this is what I get when I double click the comparison.png.bz2 file.
I can view and extract my file but I can not use it without extracting it. I prefer to do my things in the command-line, so I will extract my image using the bzip2 utility. Type the ‘bunzip2 file_name‘ like shown in Figure 4 to decompress the file you compressed with the bzip2 utility. The bunzip2 utitlity is used to decompress a file that has been compressed with the bzip2 utility.
If I run the ‘ls‘ command the comparison.png file will show up.
We went through a simple example to learn the importance of file compression. We compress files to transfer them through slow internet connections, to attach large files in emails and to save space in general.
Did you know that the Linux man pages are compressed with the gzip utility? If not, you know now. Linux stores manual pages in gzip format to save disk space.
Like us on Facebook
This week Top Posts
- Top Things To Do After Installing Ubuntu 13.10 'Saucy Salamander' : Ubuntu 13.10 Saucy Salamander will be released on coming October 17th with many new salient featur...0 comments |
- Manage Databases And Hosted Servers Remotely With DbNinja : Database administration via command line is bit difficult for newbie system and database administrat...0 comments |
- Install Sayonara Player In Elementary OS / Ubuntu / Linux Mint : Sayonara is a small, clear and fast audio player for Linux written in C++, supported by the Qt frame...0 comments |
- How To Install Linux Kernel 3.12.4 In Ubuntu : Linux Kernel 3.12.4 has been officially released with fixes for inet6_init() cleanup order, seqlock ...0 comments |
- How To Upgrade From Ubuntu 13.04 Raring To Ubuntu 13.10 Saucy Salamander : Ubuntu 13.10 Saucy will be released on October 17th. Hope it will come with lot of improvements and ...0 comments |
- Firefox 26 Has Been Released, How To Install It In Ubuntu And Its Derivates : Hi guys, Firefox 26 has been released for Windows, Mac OS X, Linux and Android devices. It brings m...0 comments |
- How To Install Linux Kernel 3.12.4 In Ubuntu
- Firefox 26 Has Been Released, How To Install It In Ubuntu And Its Derivates
- How To Install Brasero In Elementary OS ‘Luna’
- Install Sayonara Player In Elementary OS / Ubuntu / Linux Mint
- Manage Databases And Hosted Servers Remotely With DbNinja
- Install FrostWire 5.6.9 In Elementary OS ‘Luna’/ Ubuntu / Linux Mint
- Setup IT And Asset Management System With GLPI On Debian/Ubuntu
- How To Configure Linux Clients To Authenticate Using OpenLDAP
- How To Install Netflix In Ubuntu
- cowsay And fortune Combined Together
This work by unixmen.com is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Copyright © 2008-2013 Unixmen.com .