We’ve zipped files from the Linux command line; now, let’s unzip them. This short article will show you how.
Zipping files is common parlance for compressing one or more files or directories into a .zip file – a compressed file format.
The Unzip Command
The unzip command may not be installed on your system by default. If it isn’t, it can be installed on Debian/Ubuntu-based OS by running:
sudo apt install unzip
… or on Redhat/Centos/Fedora by running:
sudo yum install unzip
Unzipping Files in Linux with the Unzip Command
unzip is incredibly easy to use – you supply it with the path to a .zip file, and it unzips/decompresses the files:
Specifying Output Directory
By default, unzip will extract the files to the current working directory.
You can also specify the directory the unzipped files are written to with the -d option:
unzip /path/to/file.zip -d /path/to/output/directory
Passworded .zip Files
If you want to decompress a .zip file that was created with a password, use the -P option:
unzip -P thePassword /path/to/file.zip
However, it is best not to type passwords directly into the command line (as it may be saved in the command history). Instead, if a password is required, the unzip command will prompt for it to be more safely entered.
Overwriting Files when Extracting
If a file being extracted already exists at the destination path, you will be prompted as to whether you wish to overwrite it.
To overwrite any existing files during extraction, use the -o option:
unzip -o /path/to/file.zip
To not overwrite any existing files during extraction, use the -n option:
unzip -n /path/to/file.zip
Listing the Contents of a Zip File
List the contents of a zip file without extracting the files:
unzip -l /path/to/file.zip
If there is a file (or files) you don’t wish to have extracted, use the -x option to exclude them:
unzip -l /path/to/file.zip -x excludeFile1 excludeFile2
One or more filenames can be specified to be excluded, each separated by a space.
When running, each file that is successfully decompressed is listed. You can suppress that output with the -q (quiet) option:
unzip -q /path/to/file.zip
You can view the full user manual including all options and functions by running: