Just downloaded a .zip file from the internet. I want to use the terminal to unzip the file. What is the correct way to do this?
Just downloaded a .zip file from the internet. I want to use the terminal to unzip the file. What is the correct way to do this?
If the
unzip
command isn't already installed on your system, then run:After installing the unzip utility, if you want to extract to a particular destination folder, you can use:
If the source and destination directories are the same, you can simply do:
You can simply use
unzip
.Install it:
And use it:
A more useful tool is
7z
, which zips and unzips a range of compression formats, notablylzma
, usually the protocol offering the highest compression rates.This command installs
7z
:This command lists the contents of the zip:
This command extracts the contents of the zip:
You can use:
to extract to
yourpath/somedir
If you want to extract to an absolute path, use
Using scripting tools: Perl and Python
Many answers here mention tools that require installation, but nobody has mentioned that two of Ubuntu's scripting languages, Perl and Python, already come with all the necessary modules that allow you to unzip a zip archive, which means you don't need to install anything else. Just use either of the two scripts presented below to do the job. They're fairly short and can even be condensed to a one-liner command if we wanted to.
Python
Usage:
or
Perl
Usage:
or
See also
If the source and destination directories are the same, you can simply do:
I prefer
bsdtar
tounzip
/zip
. For extracting, they are pretty similar:However for zipping,
bsdtar
wins. Say you have this input:and want this in the zip file:
This is easy with
bsdtar
:zip does not have the
-d
option like unzip, so you have no way to achieve the above unless youcd
first.Here is the detailed description of options that I find useful:
Follow these instructions: http://www.codebind.com/linux-tutorials/unzip-zip-file-using-terminal-linux-ubuntu-linux-mint-debian/