Skip to main content

How To Compress And Extract Files In Linux | Tar, Gzip, Gunzip Commands


In this article in the Linux Lexicon series, we shall discover how to compress and extract files in Linux. We will be focusing upon the tar, gzip, and gunzip commands along with their associated options. These commands have simple syntax to make the task easier.

While there are special software designed for the compressing and extracting files in Linuxbut there is no need to bother yourself with the tardy process of finding, choosing and installing one because everything can be done through the Terminal itself. Let’s find out how:

Compressing and extracting files in Linux:

Tar Command

The tar command is primarily used to bundle the required files or directories into an archive. Depending on the option used we can also use the tar command to extract or list the contents of a tar archive. The syntax for using the tar command for archiving and compressing files is as follows:
Some of the most common options used along with the tar command are as follows:
– Create a tar archive
– Extract files from the archive
– Display the table of contents (list)
– Be verbose
– Use compression
– Used to specify the file to use
Now before all of this goes over your head, let me explain it with the help of an example. Suppose I have a directory named “Archive&Compress” whose tar archive I wish to create, here is how it can be done:
Archive and Compress Files in Linux tar1
In order to create the archive in Linux and use compression, we use the ‘c‘ option and use the ‘f‘ option to specify the file. When the archive “ac.tar” in our example has been created, we can use the ‘t‘ option to list the contents starting with the name of the directory and the files included within the directory.
Now I will teach you how to extract the content of the archived file. Suppose I wish to extract the contents of the tar archive to my desktop, here is how I will proceed:
Archive and Compress Files in Linux tar2
You will notice that we used the ‘x‘ option for extracting the contents. Now in case you want a verbose listing of what the extract operation is doing, then you can use the ‘v‘ option, like this:
Archive and Compress Files in Linux tar3

Gzip and Gunzip Command

The next part of our tutorial on how to archive and compress files in Linux focuses on compressing files. In order to compress files and save memory space, we use the gzip command. In order to uncompress the files, we use the gunzip command. The format for using the commands is:
Consider the following example, suppose I wish to compress a file named “impress2”, then I will proceed as follows:
Archive and Compress Files in Linux gzip
Now in order to uncompress it, I will use the gunzip command, which works in the following manner:
Archive and Compress Files in Linux gunzip
Note: The du command has been used to find out the estimated space used by each file
You can also check out the complete Linux command reference. Happy learning.
Got any doubts, queries of your own, or any suggestions on the topics that you would like us to cover? Share your views with us inside comments below.

Comments

Follow Us

WHAT'S HOT

Best Gaming Linux Distros You Need To Try In 2017

Gaming on Linux scene is improving each year with better hardware support and increasing support from game developers. Apart from established distros like Ubuntu and Arch Linux, gamers are using gaming Linux distros like Steam OS to get a better experience. The other It’s gaming operating systems are Sparky Linux – Gameover

Learn How To Activate iOS 11 Dark Mode

Apart from all the major iOS 11 features and changes, there are some hidden and minor features as well. In this release, Apple has included a feature named Smart Invert Colors, which is the closest you can get while looking for an iOS 11 dark mode.

Microsoft Set To Put Fingerprint Sensor In Keyboard Keys

According to a new patent titled “ Keyset Fingerprint Sensor ,” Microsoft might be working to integrate the fingerprint sensor in keyboard keys. The fingerprint recognition might be done

Latest Linux Distribution Releases List

This list is prepared with the inputs from different Linux distro developers and the official release notes. But, before going ahead and taking a look at latest releases, don’t forget to check out our useful lists of best Linux distros of 2017: Best Linux Distro For Beginners Best Linux Distro For Gamers Best Lightweight Linux Distros Best Operating Systems For Ethical Hacking Linux Distribution Releases (July 2017) Linux Mint 18.2 Release Date: July 2nd, 2017 You can read about Linux Mint 18.2 Sonya in detail  on 9jabreezeland . 4MLinux 22.0 Release Date: July 1st, 2017 4MLinux 22.0 is the latest stable release. It comes loaded with LibreOffice 5.4.0.1, GIMP 2.8.22, Dropbox 28.4.14, Firefox 54.0, Chromium 59.0.3071.86, etc. The biggest change comes with 4MLinux Server, which is a lightweight and fast server Linux distro. You can read more about 4MLinux 22.0  here . Netrunner 17.06 Release Date: July 1st, 2017 Netrunner 17.06, codenamed Daed...