Guide to Compressing and Extracting Files in Linux

0

Guide to Compressing and Extracting Files in Linux

This post is geared towards unearthing the techniques that can be used to compress and extract files in Linux. In this post, we will emphasize on tar, gzip and gunzip commands alongside the different options that can be employed with them. These commands boast a simple syntax that renders their application quite simple.

Linux has numerous tools specifically created from compressing and extracting zipped files. However, there is no need to waste your time looking for a handy tool that can assist you in zipping and unzipping archive files. All this process can be accomplished right from the Terminal itself. Let’s get going then!

TAR Command

The tar command is basically used to cluster the requisite files or folders into an archive. It can also be utilized to extract or list the contents of a tar archive. The syntax for using the tar command for compressing and decompressing files is as follows:

Tar [-] clxlt f tarfile [pattern]

Here are some of the most commonly used options with the tar command:

c – Create a tar archive

x – extract files from the archive

t – Display the table of contents (list)

v – Be verbose

z – Use compression

f – Used to specify the file to use

Hey, don’t freak out! Let us give you a comprehensive example to explain all this apparently messy business. Assume that there is a directory named “Archive&Compress”. We intend to create its tar archive. The following process can be followed to carry it out.

The “c” option is used to compress the archive in Linux and “f” option is used to specify the file. Once the archive file “ac.tar” has been created, the “t” option can be used to enlist the contents starting with the name of the directory and files included within it.

Now, let us discuss the procedure to extract the contents of a zipped file. Assume that we intend to decompress the contents of a zipped file to the desktop. We can follow the following procedure:

You will have observed that we have employed the “x” option to decompress the contents of an archived file. You can employ the “v” option to view a verbose listing of the operation.

GZip and Gunzip Commands

Now, we will be discussing how to compress files in Linux. The gzip command is used to compress files and save up some storage space. The gunzip command is used to decompress a file. Here is the syntax for the two commands:

gzip/gunzip filename

Now, let us assume that we intend to compress a file named “impress2”. We may follow the below mentioned procedure.

We will employ the gunzip command to decompress the file which will work as given below:

We have used the du command in this example to determine the approximate space taken up by each file.

You can also go through the main pages of these commands to get more insight into compressing and archiving files in Linux and explore other options that can also be used along with them. Here is the complete Linux command reference for more information.

If you are still not sure, have some queries or want to share your experience with us, do not hesitate to leave us your comment in the comments section below.

We will be happy to hear your thoughts

Leave a reply