How To Zip And Unzip Files In Linux Guide


For those unaware, zipping means compressing a file or multiple files of different formats into a single file, such that it occupies less space and can be transferred using less bandwidth. Unzipping a file means extracting all the compressed files from a zip file. That said, let’s look at how you can zip and unzip files in Linux:

How to Zip Files in Linux (GUI Method)

The GUI method to zip and unzip files is easier compared to the CLI method but lacks various options and features which may be useful for many users. The method shown here will work for all Linux distributions with any file manager. For this tutorial, we are using the Nautilus file manager in Ubuntu 20.04 LTS version.

  1. First, open any file manager of your choice and navigate to the directory where your files are located.
  2. Then, select the files you want to add to the zip file.
  3. Right-click on any one of the selected files and select “Compress.”
  4. Here, you need to give your compressed file a new name and select the file format – .zip, .7z or .tar.xz. Finally, click on “Create” at the top right.
  5. And that’s it. The compressed file will be saved to the same directory with the selected format.

How to Unzip Files in Linux (GUI Method)

There are three different ways to unzip an archive file using the GUI File manager on Linux:

1. Extract All Files in the Same Directory

First, open the file manager and locate the archive file.

Then, right-click on the file and select “Extract Here.” This will extract your files into a new sub-directory with the same name as the archive file.

2. Unzip All Files in a Different Directory

First, open the file manager and locate the archived file.

Then, right-click on the file and select the “Extract To” option. It will open a new dialogue box.

Select the path to which you want to unzip all the files from the left pane and click on “Select.”

All your files will be extracted in a new sub-directory with the same name as the archived file.

3. Unzip Only Selected Files

First, open the file manager and locate the archive file. Then, double-click on the file. This will open the Archive Manager.

Select multiple files by holding down the “CTRL” key while clicking on the file names you want to select. Then, click on “Extract” in the top left corner.

In the new dialogue box, choose the path and click on “Select” in the top right corner.

All your files will be extracted in a new sub-directory with the same name as the archived file.

How to Zip Files Using Linux Command Line

The CLI method of compressing and decompressing files is not only faster compared to the GUI method, but it also provides a lot of options to tinker with files. While there are multiple commands to compress and decompress files, zip and unzip are the most common commands as they are cross-platform and have wide online support.

1. Install Zip and Unzip Packages

By default, both the packages – zip ad unzip – come pre-installed on most distros. Use the commands below to install them, if it is not available by default:
sudo apt install zip sudo apt install unzip

2. Compress Files Using Zip Command in Linux

The basic syntax to compress files using the zip command is as follows:
zip