How to Zip and Unzip Files and Folders in Ubuntu?

Learn how to zip and Unzip files and folders in Ubuntu easily with our step-by-step guide. Discover various command line and GUI options for zipping and unzipping files, including the popular tar and gzip tools.

Updated: 24 Jan, 24 by Susith Nonis 12 Min

List of content you will read in this article:

Encountering zip files usually tempts us to archive our files in a folder, as we can save disk space and network bandwidth. Zip files and folders in Ubuntu (Ubuntu Linux operating system - a Linux distribution developed by Canonical) help us compress multiple files into one. But you may not know how to do that. This article reviews convenient methods for zipping files and folders in Ubuntu. Learn more about Ubuntu: Delve deeper into the essence of Ubuntu and its significance.

The standard tar and gzip utilities created many Ubuntu Linux file archives with the "tar.gz" extension. Although gzip has the same name as Windows' built-in file extractor, PKUNZIP, WinZip, or 7-Zip, it does not produce compressed archives compatible with these utilities. Linux and non-Linux systems, such as Windows and Mac OS X, can extract standard archives created by Ubuntu's zip command line utility. Learn more about zipping files: Explore our comprehensive guide on mastering the Zip command in Linux!

Follow the steps below to learn how to add a zip file in Ubuntu:

  1. Tap on the "Dash" icon and in the search box, type "terminal". The "Terminal" application icon will appear. Click on it.
  2. Use the cd command to navigate to the zip file's folder. When you are at the command prompt, type "cd Documents" and press Enter if your file is located in the "Documents" folder. Master the cd Command: Learn How to Navigate in Linux
  3. Ubuntu's terminal command line allows you to create a zip archive, add files to the archive, and build the zip archive by typing the “zip” command. For example, to create a zip archive named “moneydocs” that contains the file "bank.doc", type the following commands at a terminal prompt and then press the "Enter" key: zip moneydocs bank.doc
  4. Now you need to confirm that your zip file has been created. To do so, type "ls *.zip" at the command prompt. Then tap the “Enter” key.

In addition to creating zip files, compressing a folder in zip format is essential for sharing multiple files with someone else. Zip folders are offered to prevent the loss of our data in operating systems(software that manages computer hardware resources), so you should learn how to zip a folder in Ubuntu. 2 methods for zipping a folder in Ubuntu are using the Gnome graphical interface environment and using the command line. First, let`s start with the command line zipping method:

1.   Zip folder in Ubuntu using the command line

To zip a folder in Ubuntu, the zip command-line utility must be installed on your system, as it’s necessary for file compression. So, before anything, check if it has been installed on your system. Refer to our Updated Cheat Sheet for Basic Linux Commands with Practical Examples. There is no default installation of this zip utility in most Linux distributions (operating systems based on the Linux kernel and often core GNU components).

You can use the Ubuntu (Linux distribution developed by Canonical) official apt repository if you need to install the zip command-line utility. Typing the command mentioned below helps you to install it too:

$ sudo apt update

$ sudo apt install zip

Now that you have installed the zip utility use the command below to check the installed version:

$ zip –version

You can zip a folder with the zip utility using the syntax below:

$ zip options archive-name.zip folder-name

For instance, if you want to zip a folder named ‘MyFolder’, the below-mentioned syntax will create a zip archive of this folder:

$ zip -r MyFolder.zip MyFolder

Upon successfully compiling all files with the zip utility and adding them to the .zip archive, the directory's contents will be displayed on the terminal.

Multiple files and directories can be included in the same zip archive, as well as multiple directories and folders. If you want to create multiple zip archives, use the following command:

$ zip -r archivefolder.zip MyFolder1 MyFolder2 file1.txt file2.txt

$ zip -r MyDocsFolder.zip MyDocsFolder PersonalFolder file1.txt file2.txt file3.txt

You may have private or sensitive files and information you want to keep secure. We mention a command that needs a verification password to access files. For storing your private files, use this command:

$ zip -e  archivename.zip directory_name

1. Create split zip files in Ubuntu

Occasionally, you need to upload files that are only 100 kb in size to another server or file hosting service. For instance, you have 2 MB of data to upload, but it only supports 100 kb files.

By using the option '-s' followed by the specified archive file size limit, you can create a split archive file. Once you reach the specified archive file size limit, the below command creates a new zip archive file in the home directory.

$ zip -s 100k -r archivename.zip directory_name

Don't miss out on this opportunity to simplify your Linux file size management. Say goodbye to frustration and hello to efficiency! Ready to leap? Click here to learn How to Find File Size in Linux and revolutionize your Linux experience.

2.   Zip folder in Ubuntu using Gnome GUI

Another method of zipping a folder in Ubuntu is using the Gnome graphical desktop environment. If you can`t use the command line, perform the following steps:

  1. You can zip a folder using the Gnome desktop and navigate to that folder.
  2. Select the folder by right-clicking on it. A drop-down list will appear; select the 'compress' option from the list.
  3. Click on 'Create' after selecting the '.zip' extension and giving the zip archive a suitable name.

Now you can see that the compressed archive is created in the current directory where the main folder is located.

When downloading large files from the internet, it is often convenient to compress them into a single zip file. However, after downloading, you may need to extract multiple zip files on Ubuntu. This tutorial will guide you through the process of unzipping multiple zip files on Ubuntu. Explore our comprehensive guide on using Unzip in Linux

  1. Open the terminal: Open the terminal by pressing Ctrl + Alt + T or by searching for “Terminal” in the Ubuntu dash.
  2. Navigate to the directory containing the zip files: Use the cd command to navigate to the directory where the zip files are located. For example, if the zip files are located in the “Downloads” directory, you would type the following command:

cd Downloads/

  1. Install the unzip utility: If you haven’t already, you’ll need to install the unzip utility by running the following command:

sudo apt-get install unzip

  1. Unzip the files: To unzip all the zip files in the directory, type the following command:

unzip '*.zip'

This will extract all the files from the zip files into the same directory. If you want to extract the files into a different directory, replace the “.” in the command with the path to the directory you want to extract the files to.

  1. Verify the extraction: Once the extraction is complete, verify that all the files have been extracted correctly by using the ls command to list the files in the directory.

ls

You should see a list of all the files that were extracted from the zip files.

In this tutorial, we will guide you on how to test if a ZIP file is valid on Ubuntu.

  1. Open the terminal: Open the Ubuntu terminal by pressing the Ctrl+Alt+T keys simultaneously or search for Terminal in the Ubuntu dash.
  2. Navigate to the directory where the ZIP file is stored: Use the cd command to navigate to the directory where the ZIP file is located. For example, if the ZIP file is stored in the Downloads directory, use the following command:

cd Downloads/

  1. Install the unzip utility: If you haven't already installed the unzip utility, you can do so by running the following command in the terminal:

sudo apt-get install unzip

  1. Verify the ZIP file: To test the validity of the ZIP file, use the -t option with the unzip command as follows:

unzip -t filename.zip

Replace filename.zip with the name of the ZIP file you want to verify.

  1. Review the output: After running the above command, the unzip utility will start verifying the ZIP file's validity. If the ZIP file is valid, the terminal will display the message No errors detected in compressed data of filename.zip.

If the ZIP file is invalid or corrupted, the terminal will display the message Zip file integrity test failed.

To list the contents of a zip file on Ubuntu, you can use the command line interface. Here are the steps to do so:

  1. Open the Terminal on your Ubuntu system.
  2. Navigate to the directory that contains the zip file using the “cd” command. For example, if the zip file is located in the “Documents” folder, type: “cd Documents” and press Enter.
  3. Type the following command in the Terminal to list the contents of the zip file:

unzip -l filename.zip

Replace the “filename.zip” with the name of the zip file that you want to list the contents. Press Enter.

  1. You will now see a list of all the files and directories inside the zip file.

Note: If the “unzip” command is not installed on your Ubuntu system, you can install it using the following command:

sudo apt-get install unzip

After installing, you can proceed with the above steps to list the contents of the zip file.

When unzipping a zip file on Ubuntu, you may sometimes want to exclude certain files or directories from being extracted. Here's a step-by-step guide on how to exclude files when unzipping a ZIP file on Ubuntu:

  1. Open the Terminal application on your Ubuntu system.
  2. Navigate to the directory where the zip file you want to extract is located using the cd command. For example, if the zip file is located in the Downloads folder, type cd Downloads, and press Enter.
  3. To extract the contents of the zip file, use the following command:

unzip filename.zip

Replace filename.zip with the name of the zip file that you want to extract. Press Enter.

  1. To exclude specific files or directories from being extracted, use the -x option followed by the name of the file or directory you want to exclude. For example, if you want to exclude a file called example.txt and a directory called example_dir from being extracted, use the following command:

unzip filename.zip -x example.txt example_dir/

Press Enter.

Note: Make sure to specify the correct path to the file or directory you want to exclude. If the file or directory is located in a subdirectory of the zip file, you will need to include the path to the subdirectory as well.

  1. The extracted files will now appear in the same directory as the zip file. Any files or directories that were excluded will not be extracted.

Compressing files always helps us to save disk space and bandwidth. It`s also useful for sharing multiple files with others in a convenient way. Now you can zip files and folders in Ubuntu (free operating system) as we explained the methods to create them using the command line and Gnome graphical desktop environment. To choose a suitable method, you must take into account your requirements. I hope the information about zipping a folder using the zip command will be helpful for you.

Right-click on the file or folder you want to zip and select “Compress”. Choose the archive format and click “Create”.

Right-click on the archive file and select “Extract here” or “Extract to”. The files will be extracted to the current directory.

Yes, when creating the zip file, check the “Encrypt” box and set a password.

Right-click on the archive file and select “Extract here” or “Extract to”. Enter the password when prompted.

Yes, select all the files and folders you want to zip and right-click. Select “Compress” and choose the archive format.

Yes, right-click on the archive file and select “Open with Archive Manager”. Double-click on the file you want to extract and select “Extract”.

Susith Nonis

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited 'master chef'.