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 (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.
How to zip a file in Ubuntu?
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.
Follow the steps below to learn how add zip file in Ubuntu:
Tap on the "Dash" icon, and in the search box, type "terminal". The "Terminal" application icon will appear. Click on it.
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.
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
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.
How to ZIP a folder in Ubuntu?
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. There is no default installation of this zip utility in most Linux distributions (operating system 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.
How to zip multiple folders in Ubuntu?
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
How to create a zip file with a password in Ubuntu?
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
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:
- You can zip a folder using the Gnome desktop and navigate to that folder.
- Select the folder by right-clicking on it. A drop-down list will appear; select the 'compress' option from the list.
- 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.
How to Unzip Multiple zip Files
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.
- Open the terminal: Open the terminal by pressing Ctrl + Alt + T or by searching for “Terminal” in the Ubuntu dash.
- 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:
- 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
- Unzip the files: To unzip all the zip files in the directory, type the following command:
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.
- 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.
You should see a list of all the files that were extracted from the zip files.
How to Test if a ZIP File is Valid
In this tutorial, we will guide you on how to test if a ZIP file is valid on Ubuntu.
- Open the terminal: Open the Ubuntu terminal by pressing the Ctrl+Alt+T keys simultaneously or search for Terminal in the Ubuntu dash.
- 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:
- 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
- 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.
- 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.
How to List the Contents of a Zip File
To list the contents of a zip file on Ubuntu, you can use the command line interface. Here are the steps to do so:
- Open the Terminal on your Ubuntu system.
- 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.
- 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.
- 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.
How to Exclude Files When Unzipping a 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:
- Open the Terminal application on your Ubuntu system.
- 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.
- To extract the contents of the zip file, use the following command:
Replace filename.zip with the name of the zip file that you want to extract. Press Enter.
- 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/
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.
- 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.
How do I zip a file or folder in Ubuntu?
Right-click on the file or folder you want to zip and select “Compress”. Choose the archive format and click “Create”.
How to unzip a file in Ubuntu?
Right-click on the archive file and select “Extract here” or “Extract to”. The files will be extracted to the current directory.
Can I password-protect my zip file?
Yes, when creating the zip file, check the “Encrypt” box and set a password.
How do I unzip a password-protected zip file?
Right-click on the archive file and select “Extract here” or “Extract to”. Enter the password when prompted.
Can I zip multiple files and folders at once?
Yes, select all the files and folders you want to zip and right-click. Select “Compress” and choose the archive format.
Can I extract specific files from a zip file?
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”.
People also read:
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'.