Compressing files is an excellent way to save storage and bandwidth while transferring files physically or over a network. There are numerous file compression formats like ZIP, RAR, and TAR. Undoubtedly, ZIP is the most commonly used compression format, especially within the Windows and Linux ecosystems.
On Linux-based operating systems, you can use unzip, a popular command-line tool for zipping and unzipping files.
Installing unzip on Linux
The unzip command is necessary to perform zipping and unzipping tasks in Linux. You can install unzip on almost every Linux distro using the default package manager.
On Ubuntu and Debian, run:
sudo apt install unzip
To install unzip on Fedora, CentOS, or other RHEL-based distros:
sudo yum install unzip
On Arch Linux and its derivatives:
sudo pacman -S unzip
If you don't fancy unzip, you can even install 7-Zip on your Linux PC.
Unzipping Files Using unzip
The unzipping process extracts all the files present inside a ZIP file. These files are extracted to the current directory by default, but you can change this by specifying a different directory in the unzip command.
Use the following command to unzip files in Linux:
unzip filename.zip
The aforementioned command prints the name of all the extracted files in the output. You can mute the output of the command using the -q flag:
unzip -q filename.zip
The -q stands for quiet and hides the output generated by unzip.
Unzip Files to a Different Directory
You can extract the ZIP file to a separate folder to keep the current directory prim and proper. This also arranges the extracted files and ensures they don't get mixed with other files present in the current directory.
To extract files to a different directory, use the -d flag. The -d flag stands for Directory and takes a relative or absolute path as the argument.
unzip filename.zip -d /directory/location
Unzip a Password-Protected ZIP File on Linux
Protecting ZIP files using a password is a common practice to ensure security and maintain confidentiality. You can unzip a password-protected ZIP archive using:
unzip -P your_password filename.zip
...where your_password is the password for the archive.
Exclude Files When Unzipping
If the ZIP archive contains files you don't want to unzip, use the -x flag with the command:
unzip filename.zip -x exclude1.file exclude2.file
Extracting ZIP Files Graphically on Linux
To unzip a file without using the command line, you can use the traditional Extract method provided in almost every mainstream Linux desktop environment.
Open the folder containing the archive, double-click the file, and click on the Extract button at the top left of the window.
Once you click on the button, a dialog box will open asking you for the location where you would like to save the extracted file. In this prompt, you have options to Keep Directory Structure, Do not overwrite newer files, and Extract All Files. You can choose the relevant options before proceeding.
Select the location and click on the green Extract button, located at the top right of the dialog box.
This way, you can unzip a file at any location using a graphical interface. The archive manager will extract all the files at the specified location (depending on the options you selected).
This method will only work if your system has a preinstalled archive manager. Most Linux desktop environments have a default archive manager that you can use to extract and create ZIP files.
Working With Compressed Archives on Linux
Compression can save you plenty of time and storage if you frequently transfer multiple files locally or even online. You can zip the files using the simple zip command included in the unzip utility. The same unzip utility helps users in extracting ZIP files, making these commands useful in the long run.