In this article, we will explain how to use the unzip command in Linux to easily list, test and extract compressed ZIP archives.
So you’ve been sent a zip file and now you’re stuck figuring how to unzip it’s content on Linux? You can use the unzip command to extract (unzip) the file on Linux.
First you have to install
unzip, because it is not installed by default in most Linux distributions.
Install unzip command on Fedora / CentOS / Redhat
yum install unzip
apt install unzip
How to Unzip a ZIP File in Linux with the unzip Command
unzip command in Linux is absolutely simple. You need to tell
unzip the name of the ZIP file which you want to unzip.
For example, in the directory, where you have zip file named
my-archive.zip, to unzip it the command would be:
Archive: my-archive.zip extracting: file1.txt extracting: file2.txt
Just like zip,
unzip has a
-q (quiet) option, so that you do not need to see the file listing as the files are extracted.
unzip -q my-archive.zip
In addition, a good practice is to unzip to directory in Linux command line. This way, all the extracted files are stored in the directory you specified. If the directory doesn’t exist, it will create one.
unzip my-archive.zip -d my_files/
Archive: my-archive.zip extracting: my_files/file1.txt extracting: my_files/file2.txt
You can list the content of the zip file without even extracting it with the
unzip -l my-archive.zip
Archive: my-archive.zip Length Date Time Name --------- ---------- ----- ---- 0 2020-08-25 23:37 file1.txt 0 2020-08-25 23:37 file2.txt --------- ------- 0 2 files
Sometime you may want to test a zip archive without extracting it. To test the validity of the zip file, pass option
-t as shown below.
unzip -t my-archive.zip
Archive: my-archive.zip testing: file1.txt OK testing: file2.txt OK No errors detected in compressed data of my-archive.zip.
This option extracts each specified file in memory and compares the CRC (Cyclic Redundancy Check, an enhanced checksum) of the expanded file with the original’s stored CRC value.
Feel free to leave a comment if you have any questions.