More and faster are always two things we want, especially when it comes to data. The problem is that “more” and “faster” are usually at odds, so we have file compression. There are several ways to zip and unzip files in Linux, and we’re going to show you the methods behind them.

7 Ways to Zip and Unzip Files in Linux image 1

Zip and Unzip Using Zip in Linux

Linux has several compression tools built into almost every distribution, commonly known as Linux distros. Zip is likely the most popular. The Zip utility can be used in the graphical user interface (GUI) or the terminal.

Table of Contents

    Zip in the Linux GUI

    1. Navigate to the files to be compressed and select them. Then right-click and select Compress.
    7 Ways to Zip and Unzip Files in Linux image 2
    1. Enter a name for the zipped archive. Note that you can also choose two other types of compression. This may vary between distros.
    7 Ways to Zip and Unzip Files in Linux image 3
    1. Soon you’ll see your zipped archive. Note that the archive size is much less than the total size of the files put into it.
    7 Ways to Zip and Unzip Files in Linux image 4

    Unzip in the Linux GUI

    1. Find the zipped archive to unzip and right-click on it. Select Extract Here or Extract to…. Extra Here puts the contents into this directory. Extract to… allows you to select somewhere else to put the contents.
    7 Ways to Zip and Unzip Files in Linux image 5

    The files are extracted. Notice that they’re back to their full size of 100 MB each.

    7 Ways to Zip and Unzip Files in Linux image 6

    Archive Manager to Unzip in the Linux GUI

    Some Linux distros have other ways to unzip built into them. In this example, you can use Archive Manager.

    1. Right-click on the archive and select Open With Archive Manager.
    7 Ways to Zip and Unzip Files in Linux image 7
    1. Highlight the files to extract by single-clicking on them. You can select one, a few, or all of them. Then select Extract in the top-left corner.
    7 Ways to Zip and Unzip Files in Linux image 8
    1. At this point, you can choose where to extract the files using the file manager. Then select Extract in the top-right corner.
    7 Ways to Zip and Unzip Files in Linux image 9
    1. When the extraction is done, you can either carry on or Show the Files.
    7 Ways to Zip and Unzip Files in Linux image 10

    The file is back at its full size. A copy is left inside the archive.

    7 Ways to Zip and Unzip Files in Linux image 11

    Zip Files in Linux Terminal

    Open the terminal and navigate to the directory where the files to be zipped are located. Enter the command zip ziptest.zip *

    Zip tells Linux to use the zip utility, ziptest.zip tells it the desired name for the archive, the asterisk (*) is a wildcard meaning zip all the files in this directory. 

    7 Ways to Zip and Unzip Files in Linux image 12
    7 Ways to Zip and Unzip Files in Linux image 13

    It zips the files, lists them, and says how much it has deflated or compressed them.

    7 Ways to Zip and Unzip Files in Linux image 14

    Many actions can be used with the zip command. To view them, enter zip –help, and you’ll see something like the following image.

    7 Ways to Zip and Unzip Files in Linux image 15

    Unzip Files in Linux Terminal

    In the Terminal, use the command unzip ziptest.zip, where unzip is the command and ziptest.zip is the name of the archive to unzip.

    7 Ways to Zip and Unzip Files in Linux image 16

    It will show the files being unzipped, so you know when it’s done.

    7 Ways to Zip and Unzip Files in Linux image 17

    Like the zip command, many actions can be used with the unzip command. To view them, enter unzip –help, and you’ll see something like the following image.

    7 Ways to Zip and Unzip Files in Linux image 18

    Bzip2 for Zipping and Unzipping Files in Linux

    Bzip2 is another compression utility built into most Linux distros. A major difference is that bzip2 cannot zip multiple files into one archive. Each file gets its own zipped archive.

    Zip Files in Linux Terminal With Bzip2

    Enter the command bzip2 -kv9 testfile1.txt testfile2.txt where bzip2 is the command.

    -kv9 breaks down to k means keep the originals, v means verbose so we can see what’s happening, and 9 for the highest level of compression. You can choose between 1 and 9. The higher the level of compression, the longer zipping the files takes.

    7 Ways to Zip and Unzip Files in Linux image 19

    The output tells us more than zip does, but the end result is almost the same.

    7 Ways to Zip and Unzip Files in Linux image 20

    Unzip Files In Linux Terminal With Bzip2

    Enter the command bzip2 -kvd testfile.1.txt.bz2 testfile2.txt.bz2. The -kvd options break down as k for keep the archives, v for verbose output, and d for decompress.

    7 Ways to Zip and Unzip Files in Linux image 21

    You see the files being decompressed and known when it’s done.

    7 Ways to Zip and Unzip Files in Linux image 22

    To view the bzip2 options, enter bzip2 –help, and you’ll see the following. Play around with the options on non-critical files just to see what they can do.

    7 Ways to Zip and Unzip Files in Linux image 23

    Gzip for Zipping and Unzipping Files in Linux

    This is the last of the popular compression utilities that are included with most distros. It’s lighter than bzip2 and zip for options. However, the quality of compression is still about the same.

    Zip Files in Linux Terminal With Gzip

    Enter the command gzip2 -kv9 testfile.1.txt testfile2.txt. The -kv9 options break down as k for keep the files, v for verbose output, and 9 for the highest compression level between 1 and 9.

    7 Ways to Zip and Unzip Files in Linux image 24

    As the verbose output shows, gzip works about as well as the other zipping methods.

    7 Ways to Zip and Unzip Files in Linux image 25

    Unzip Files in Linux Terminal With Gzip

    There are two ways to unzip gzip archives. One is to use the gzip, and the other is gunzip.

    For the gzip command, use gzip -kvd testfile1.txt.gz testfile2.txt.gz. Notice the d option. That means to decompress.

    7 Ways to Zip and Unzip Files in Linux image 26

    For the gunzip command, use gunzip testfile1.txt.gz testfile.2.txt.gz. The only difference from gzip is that gunzip doesn’t require options for a basic decompression.

    7 Ways to Zip and Unzip Files in Linux image 27

    What About Tar to Zip and Unzip Files in Linux?

    Why hasn’t tar been mentioned yet? It’s an archiving tool, taking a bunch of files and putting them into one archive for easy transport. Whatever the file sizes are, the size of the tar file will be about the same. 

    But if you combine a zip method with tar, then you get something really cool. You get a nicely compressed single package of files. 

    Using the other zip methods on a directory of files, you’d get a compressed archive for each file in the directory. Using tar with the gzip option on the directory compresses everything and makes one archive.

    Zip Files in Linux Terminal With Tar and Gzip

    Enter the command tar -czvf Documents.tgz Documents

    The -czvf options break down as c for create a new archive, z for compress with gzip, v for verbose output, and f for file equals archive, which means the archive maintains the file structure of the original directory. 

    The new archive must be named, which is Documents.tgz in this example. By using the .tgz file extension, others will know that this is a tar archive that has been gzipped. Finally Documents is the directory to archive and compress.

    7 Ways to Zip and Unzip Files in Linux image 28

    The output looks like the following.

    7 Ways to Zip and Unzip Files in Linux image 29

    In File Manager, you can see the tar archive and that it’s compressed.

    7 Ways to Zip and Unzip Files in Linux image 30

    Unzip Files in Linux Terminal With Tar and Gzip

    To unzip a gzipped tar archive, it’s the same tar command with slightly different options. 

    Enter the command tar -xzvf Documents.tgz Documents

    The -xzvf options break down as x for extract, z for unzip with gzip, v for verbose so we can watch it happen, and f for file=archive means keep the file structure. Documents.tgz is the archive to be unpacked and unzipped, and Documents is the directory into which you want the contents to go.

    7 Ways to Zip and Unzip Files in Linux image 31

    The results are shown in the image below. The two files are back to full size, and they are in the Documents directory.

    7 Ways to Zip and Unzip Files in Linux image 32

    To view the tar options, enter tar –help, and you’ll get several pages of options. Notice that there are different zip methods available other than gzip, so you can choose the one you like.

    Less Popular Zip Tools in Linux

    There are two more compression utilities found in most Linux distros. However, they’re not that popular. Nevertheless, they’re listed here, so you’re aware of them.

    LZMA

    LZMA is another command-line compression utility often found in Linux distros. It’s the compression algorithm used by 7-Zip.

    7 Ways to Zip and Unzip Files in Linux image 33

    XZ

    The XZ utility is a command-line compression tool often included in Linux distros. Its options are similar to those of bzip2. It’s based on the LZMA2 algorithm, which is based on LZMA.

    7 Ways to Zip and Unzip Files in Linux image 34

    More information about these utilities can be found by using the commands lzma –help and xz –help.

    Aren’t There Other Ways To Zip and Unzip in Linux?

    We’ve only gone into the compression tools built into most Linux distros. Still, Linux has several other ways to zip and unzip files. Some have GUIs, some are command-line utilities, and some can be used both with their GUI and through the command line. Do you use one of these zip tools in Linux? Which one is your favorite and why? Let us know in the comments.

    Leave a Reply

    Your email address will not be published. Required fields are marked *