Connect with us

    Hi, what are you looking for?

    Hacks

    Learn How To Compress And Extract Files In Linux

    Short Bytes: 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 compressing and extracting files in Linux, 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:

    tar [-] c|x|t f tarfile [pattern]

    Some of the most common options used along with the tar command are as follows:

    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

    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” and I want to create a tar archive for it. Here is how it can be done:

    Advertisement. Scroll to continue reading.

    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

    Also Read: 20 Quirky Things You Didn’t Know The Linux Terminal Could Do

    Gzip and Gunzip Command

    The next part of our tutorial on how to archive and compress files in Linux focuses on compressing files. To compress files and save memory space, we use the gzip command. To uncompress the files, we use the gunzip command. The format for using the commands is:

    gzip/gunzip filename

    Consider the following example, suppose I wish to compress a file named “impress2”. Here is how I will proceed:

    Archive and Compress Files in Linux gzip

    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 further check out the man pages of these commands to learn more about archiving and compressing files in Linux and discover other options associated with the mentioned commands. You can also check out the complete Linux command reference. Happy learning.

    Advertisement. Scroll to continue reading.

    Image Source: Zakharchuk / Shutterstock

    You May Also Like

    Reviews

    Microsoft has resolved 74 security issues in its software during the company’s August 2023 Patch Tuesday release. The previous month’s update tackled 132 vulnerabilities,...

    Hacks

    An economical high-voltage power supply project has been developed by Sebastian from Baltic Labs. The primary element of this endeavor is a commercial power...

    Hacks

    The issue of compatibility centers around the POPCNT CPU function. TheBobPony’s posts on Twitter uncovered that this function is found in several Windows 11...

    Hacks

    The choice to utilize USB storage was influenced by the nonexistence of Bluetooth and the substandard audio input port in the dated entertainment system....