How to Unzip Files in Linux with the unzip Command

Linux unzip

We’ve zipped files from the Linux command line; now, let’s unzip them. This short article will show you how.

Zipping Files

Zipping files is common parlance for compressing one or more files or directories into a .zip file – a compressed file format.

We cover how to do that in this article, so there’s no need to repeat too much of it here.

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

Unzipping

unzip is incredibly easy to use – you supply it with the path to a .zip file, and it unzips/decompresses the files:

unzip /path/to/file.zip

Simple!

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

Excluding Files

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.

Suppressing Output

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:

man unzip

 

SHARE:
nv-author-image

Brad Morton

I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

Leave a Reply

Your email address will not be published. Required fields are marked *