×
unzip linux files folders guide and tutorials

Zip (or Unzip) is one of the most popular and most widely used tools that can be used to create compressed archive files.

You can easily Zip and Unzip single or multiple files using this tool. Unzipping is a process of extracting all the files from the zip archive. If files in the archive were also compressed, unzip command will also uncompress them.

In this tutorial, we will show you how to unzip a file in Linux with several examples.

Install Unzip

By default, unzip package is not installed in any Linux operating systems. So you will need to install it on your system.

To install unzip on Ubuntu/Debian operating system, run the following command:

apt-get install unzip -y

To install unzip on CentOS/RHEL/Fedora operating system, run the following command:

yum install unzip -y

After installing unzip, you can see the installed version of unzip using the following command:

unzip -v

You should get the following output:

Latest sources and executables are at ftp://ftp.info-zip.org/pub/infozip/ ;
see ftp://ftp.info-zip.org/pub/infozip/UnZip.html for other sites.
Compiled with gcc 4.8.2 for Unix (Linux ELF) on Nov 9 2015.


UnZip special compilation options:
ACORN_FTYPE_NFS
COPYRIGHT_CLEAN (PKZIP 0.9x unreducing method not supported)
SET_DIR_ATTRIB
SYMLINKS (symbolic links supported, if RTL and file system permit)
TIMESTAMP
UNIXBACKUP
USE_EF_UT_TIME
USE_UNSHRINK (PKZIP/Zip 1.x unshrinking method supported)
USE_DEFLATE64 (PKZIP 4.x Deflate64(tm) supported)
UNICODE_SUPPORT [wide-chars, char coding: UTF-8] (handle UTF-8 paths)
LARGE_FILE_SUPPORT (large files over 2 GiB supported)
ZIP64_SUPPORT (archives using Zip64 for large files supported)
USE_BZIP2 (PKZIP 4.6+, using bzip2 lib version 1.0.6, 6-Sept-2010)
VMS_TEXT_CONV
WILD_STOP_AT_DIR
[decryption, version 2.11 of 05 Jan 2007]


UnZip and ZipInfo environment options:
UNZIP: [none]
UNZIPOPT: [none]
ZIPINFO: [none]
ZIPINFOOPT: [none]

Basic Syntax

The basic syntax of the unzip command is shown below:

unzip [OPTION] FILENAME

A brief explanation of each option are listed below:

  • -l : This option list all files available in the zip archive.
  • -t : This option is used to test the zip file whether it is zip archive or not.
  • -q : This option suppresses the printing messages during the unzipping process.
  • -v : This option gives you more detailed information during unzipping process.
  • -j : This option doesn’t create archive’s directory structure.
  • -n : This option is used to skip the extraction of all existing files.
  • -o : This option is used to overwrite existing files without prompting.
  • -P : This option allows you to specify a password to extract the password protected zip file.
  • -d : This option is used to extract files in the specified directory.
  • -u : This option extracts those files that do not already exist on disk.

How to Use Unzip

Here’s are several ways to Unzip a compressed zip file in Linux:

1. To unzip a single file use the unzip command without any option as shown below:

unzip file1.zip

You should see the following output:

Archive: file1.zip
creating: file1/
extracting: file1/file1.txt
extracting: file1/file2.txt
extracting: file1/file3.txt

Example:

2. To unzip multiple file use the following command:

unzip '*.zip'

You should see the following output:

Archive: file1.zip
extracting: file1.txt
Archive: file2.zip
extracting: file2.txt
Archive: file3.zip
extracting: file3.txt
3 archives were successfully processed.

Example:

3. To see contents of a compressed zip file you can use the option -l with unzip command as shown below:

unzip -l apt.zip

You should see the following output:

Archive: apt.zip
Length Date Time Name
--------- ---------- ----- ----
0 2020-01-02 13:07 apt/
0 2020-01-02 13:06 apt/preferences.d/
0 2020-01-02 13:06 apt/auth.conf.d/
40 2020-01-02 13:06 apt/trustdb.gpg
22174 2020-01-02 13:06 apt/trusted.gpg~
0 2020-01-02 13:06 apt/sources.list.d/
146 2020-01-02 13:06 apt/sources.list.d/mystic-mirage-pycharm-trusty.list
0 2020-01-02 13:06 apt/trusted.gpg.d/
364 2020-01-02 13:06 apt/trusted.gpg.d/ondrej-php.gpg
0 2020-01-02 13:06 apt/trusted.gpg.d/minecraft-installer-peeps-minecraft-installer.gpg~
378 2020-01-02 13:06 apt/trusted.gpg.d/minecraft-installer-peeps-minecraft-installer.gpg
0 2020-01-02 13:06 apt/trusted.gpg.d/projectatomic-ppa.gpg~
1137 2020-01-02 13:06 apt/trusted.gpg.d/projectatomic-ppa.gpg
353 2020-01-02 13:06 apt/trusted.gpg.d/osmoma-audio-recorder.gpg
6541 2020-01-02 13:06 apt/trusted.gpg.d/nilarimogard-webupd8.gpg
0 2020-01-02 13:06 apt/trusted.gpg.d/webupd8team-java.gpg~
0 2020-01-02 13:06 apt/trusted.gpg.d/nilarimogard-webupd8.gpg~
366 2020-01-02 13:06 apt/trusted.gpg.d/mystic-mirage-pycharm.gpg
7140 2020-01-02 13:06 apt/trusted.gpg.d/webupd8team-java.gpg
0 2020-01-02 13:06 apt/trusted.gpg.d/osmoma-audio-recorder.gpg~
0 2020-01-02 13:06 apt/trusted.gpg.d/mystic-mirage-pycharm.gpg~
0 2020-01-02 13:06 apt/trusted.gpg.d/ondrej-php.gpg~
2951 2020-01-02 13:06 apt/sources.list
2951 2020-01-02 13:06 apt/sources.list.save
23801 2020-01-02 13:06 apt/trusted.gpg
--------- -------
68342 25 files

Example:

4. To test whether the zip file is valid zip archive or not using the option -t with unzip command:

unzip -t test.zip

You should see the following output:

Archive: test.zip
testing: test/ OK
testing: test/file1.txt OK
testing: test/file2.txt OK
testing: test/file3.txt OK
No errors detected in compressed data of test.zip.

Example:

5. In some cases, you will need to unzip a zip file inside the specific directory. To unzip a zip file inside specific directory you can use -d option with unzip command as shown below:

unzip test.zip -d /tmp/opt/

You should see the following output:

Archive: test.zip
creating: /tmp/opt/test/
extracting: /tmp/opt/test/file1.txt
extracting: /tmp/opt/test/file2.txt
extracting: /tmp/opt/test/file3.txt

Example:

6. You can see more detail information of each file located inside the zip archive use the option -v with unzip command:

unzip -v test.zip

You should see the following output:

Archive: test.zip
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
0 Stored 0 0% 2020-01-02 13:23 00000000 test/
2241 Defl:N 193 91% 2020-01-02 13:22 e87c3e7b test/file1.txt
3716 Defl:N 207 94% 2020-01-02 13:23 2dbce9bd test/file2.txt
9070 Defl:N 255 97% 2020-01-02 13:23 e130f3cc test/file3.txt
-------- ------- --- -------
15027 655 96% 4 files

Example:

7. By default, unzip command will overwrite all the files in existing directory.To skip extraction of all existing files you can use -n option with unzip command as shown below:

unzip -n test.zip

By default, unzip command will prompt you whether you want to overwrite the existing file or not. To overwrite existing files without prompting you can use the option -o with unzip command as shown below:

unzip -o test.zip

You should see the following output:

Archive: test.zip
inflating: test/file1.txt
inflating: test/file2.txt
inflating: test/file3.txt

Example:

8. By default, unzip command will display all the files available inside the zip archive during the unzipping process. You can suppress this output using the option -q with unzip command:

unzip -q test.zip

Some zip file includes files, directories and sub-directories in the archive. Run unzip command without any option will create the same directory structure from the archive.

To unzip the zip archive without creating those directories use -j option with unzip command as shown below:

unzip -j test.zip

You should see the following output:

Archive: test.zip
extracting: 12
extracting: 1
extracting: file3.txt
extracting: 12
extracting: 122
extracting: file.txt
extracting: file1.txt
inflating: file1.txt
inflating: file2.txt
inflating: file3.txt

Example:

9. If you have a password protected zip file. You can use the option -P to specify the password with unzip command.

For example, to unzip the password protected file test.zip with password as admin run the following command:

unzip -P admin test.zip

You should see the following output:

Archive: test.zip
creating: test/
extracting: test/file1.txt
extracting: test/file2.txt
extracting: test/file3.txt

Example:

Conclusion

In the above tutorial, you learned how to unzip a zip archive in Linux with hands-on examples. You can now easily extract any zip file using unzip command. For more information, you can visit the unzip manual page at unzip.