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
We need your assistance to stay live
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 |
- News from Kaspersky Lab: Tor is protecting criminals : In a previous article I wrote a bit about Tor. Free browser, relays bouncing your IP all over the ...0 comments |
- Canonical Works with Cisco! : The Ubuntu distribution is known to everybody nowadays, right? The company behind its development ...1 comment |
- Grive: An Unofficial, Open Source Linux Client For Google Drive : A couple of months before, we have featured a Linux client for Google Drive named Syncdrive, which w...0 comments |
- Setup LDAP Server in CentOS, RHEL, Scientific linux 6.5/6.4/6.3 : In this tutorial we are going to setup LDAP server using 389 Directory Server. The 389 Directory Ser...0 comments |
- How To Access A LVM Drive / Partition in Ubuntu : Hey Guys, I installed Fedora on an external drive (LVM) recently and was trying to access it from U...0 comments |
- Download 11 Community Wallpapers Chosen For Ubuntu 14.04 “Trusty Tahr”
- Ubuntu 14.04 LTS “Trusty Tahr” Default Wallpaper Revealed!
- Canonical Works with Cisco!
- Android Intercom: An Excellent Intercom App For Bikers Or Hiking Fans
- Install Google Talk Plugin In Fedora 20
- Adding and Deleting Cluster Resources (corosync pacemaker)
- News from Kaspersky Lab: Tor is protecting criminals
- Install Satis On Ubuntu Sever 13.10/13.04
- How To Access A LVM Drive / Partition in Ubuntu
- How To Disable Remember Open Files in Sublime Text 3
This work by unixmen.com is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Copyright © 2008-2013 Unixmen.com .