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?
9 Answers
If the unzip
command isn't already installed on your system (use which unzip
to check), then run:
sudo apt-get install unzip
After installing the unzip utility, if you want to extract to a particular destination folder, you can use:
unzip file.zip -d destination_folder
If you want to extract to a directory with the same name as the zip in your current working directory, you can simply do:
unzip file.zip
-
121If you are already in the directory you want the file unzipped, omit the 2nd and 3rd arguments, i.e.
unzip /path/to/file.zip
– Severo Raz May 26 '13 at 19:13 -
2I have just used this command. This is an example. Step 1 (I changed to the directory where the zip file is stored):
cd /home/paf/Copy/Programming/Javascript/Json
Step2 (I extract the zip file in the directory I have just mentioned):unzip file.zip -d /home/paf/Copy/Programming/Javascript/Json
– pablofiumara Nov 12 '13 at 01:10 -
Is there also a "...and visit that folder in terminal" possibility of some kind? – PascalVKooten Feb 21 '14 at 11:06
-
Does this
unzip file.zip -d destination_folder
will also give all directory which start with .git and files . as start name ,Because this are hidden in Ubuntu .IF it will not extract them then how i can unzip them all from my zip file. – Herry Apr 05 '14 at 05:18 -
4
unzip
may be a default program. In other words, you may not need to install it. – noobninja May 31 '16 at 19:33 -
-
3@Aevi Check man pages
[-d exdir] An optional directory to which to extract files.
– Kenly Jan 11 '17 at 11:26 -
14Make sure you extract to a directory, unlike tar archives, you may find many people include dozens of files in their root directory of their zip files, this can make a real mess!!! – Steve May 17 '17 at 06:13
-
-
unzip is installed by default in (ubuntu) desktop, but not server and WSL. busybox comes with unzip so you don't have to install it; add
alias unzip="busybox unzip"
to "~/.bashrc" (or "~/.zshrc" if zsh is used), then relaunch terminal or login/logout. – Saftever Apr 21 '21 at 10:12
A more useful tool is 7z
, which zips and unzips a range of compression formats, notably lzma
, usually the protocol offering the highest compression rates.
This command installs 7z
:
sudo apt-get install p7zip-full
This command lists the contents of the zip:
7z l zipfile.zip
This command extracts the contents of the zip:
7z x zipfile.zip

- 137

- 1,641
- 1
- 10
- 2
-
16
-
213.10 says 7z does not exist. I think it must sudo apt-get install 7zip – nitishch Oct 26 '13 at 19:04
-
8I think the install command should be
sudo apt-get install p7zip
orsudo apt-get install p7zip-full
You need the full version to get the7z
command. The full is also the only one who handles zip and other kinds of formats out of the two. – Automatico Oct 30 '13 at 20:15 -
2could you clarify "A more useful tool"? Are you comparing to unzip? Could you provide any examples of features that make 7z more useful, and perhaps in which contexts 7z is preferred? – David LeBauer Sep 29 '15 at 22:17
-
3
-
-
@Shy Robbiani easy != useful. 7zip supports a wide array of compression algorithms while unzip if specifically tailored to . There is also dtrx, which extracts pretty much any archive format without having to specify the specifics. – Joshua Burns Oct 13 '17 at 14:40
-
-
1
-
If you getting an error with unzip like : extra bit in header , then please use 7z. 7z is way too powerful than simple unzip. – nomadSK25 Oct 29 '20 at 22:17
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
#!/usr/bin/env python3
import sys
from zipfile import PyZipFile
for zip_file in sys.argv[1:]:
pzf = PyZipFile(zip_file)
pzf.extractall()
Usage:
./pyunzip.py master.zip
or
python3 pyunzip.py master.zip
Perl
#!/usr/bin/env perl
use Archive::Extract;
foreach my $filepath (@ARGV){
my $archive = Archive::Extract->new( archive => $filepath );
$archive->extract;
}
Usage:
./perlunzip master.zip
or
perl perlunzip.pl master.zip
See also

- 105,154
- 20
- 279
- 497
-
11Thanks, exactly what I need. I don't have root and don't wanna install unzip manually from source. This also can be used with a bash one-liner which mostly will work (assuming no
'''
inside the file name):unzip(){ python -c "from zipfile import PyZipFile; PyZipFile( '''$1''' ).extractall()"; }
– mxmlnkn Feb 11 '19 at 09:50 -
2Just use ZipFile class, not PyZipFile, the latter have some specific support for compressing Python libraries – Rafał Kłys Jan 21 '20 at 11:15
-
1awesome. pretty quick where you don't have unzip and then root permission to install other binaries – Santosh Joshi Jun 30 '21 at 06:13
-
1This one line code using perl:
perl -e "use Archive::Extract;(Archive::Extract->new(archive => 'numpy-1.22.3.zip'))->extract;"
– Mohamad Hamouday Apr 06 '22 at 08:34 -
You can use:
unzip file.zip -d somedir
to extract to yourpath/somedir
If you want to extract to an absolute path, use
sudo unzip file.zip -d /somedir

- 135

- 759
- 5
- 5
If the source and destination directories are the same, you can simply do:
unzip filename.zip

- 616
- 1
- 7
- 13

- 469
- 5
- 6
I prefer bsdtar
to unzip
/zip
. For extracting, they are pretty similar:
bsdtar -x -f /one/two/three/four.zip -C /five
unzip /one/two/three/four.zip -d /five
However for zipping, bsdtar
wins. Say you have this input:
/one/two/three/alfa/four.txt
/one/two/three/bravo/four.txt
and want this in the zip file:
alfa/four.txt
bravo/four.txt
This is easy with bsdtar
:
bsdtar -a -c -f four.zip -C /one/two/three alfa bravo
zip does not have the -d
option like unzip, so you have no way to achieve the above unless you cd
first.
-
As much as I'd like to give the win to a foss tool, apparently
bsdtar
doesn't bode well with special characters like at least one in the wordBlóðstokkinn
when uncrompressing. I didn't even check when compressing. What a bummer. :/unzip
handled it without problem. – Vrakfall May 06 '19 at 14:53
Here is the detailed description of options that I find useful:
Command: unzip -[option] zip-path. -d an optional directory to which to extract files -l List archive files. -P password Use password to decrypt encrypted zipfile entries (if any). -t Test archive files with cyclic redundancy check. -u Update the existing files. -z archive comment

- 114,770

- 1,380
Follow these instructions: http://www.codebind.com/linux-tutorials/unzip-zip-file-using-terminal-linux-ubuntu-linux-mint-debian/
Install unzip
So First of all we need to install unzip on our system if it’s not installed. unzip command is used to extract files from a ZIP archive.
Run the following command to install
unzip
sudo apt-get install unzip
unzip
Syntax$ unzip [-aCcfjLlnopqtuvy] [-d dir] zipfile
Now Follow the steps below:
UnZip File
OPTION 1 – If the Zip File is in the same directory/folder in which your terminal is and we want to extract it in the present working directory.
Use the following command to achieve the above described scenario
sudo unzip zip_file_name.zip
if the zip file is protected with some password, then use the following command :
sudo ubzip -P zip_file_name.zip
Please make sure you use -P (capital P) not -p because the are different options.
OPTION 2 – If the zip file is not present in the same directory and we want to extract/unzip the file in different directory.
Use the following command to achieve the above described scenario
sudo unzip path/filename.zip -d another_path_or_same_path
if we does not use option -d the file will be extracted to present working directory.
And if the zip file is password protected we can also use
-P
.use tar Command in Linux / Unix
tar
is an acronym for Tape Archive. tar command is used to Manipulates archives in Linux/Unix. System administrators uses tar command frequently to rip a bunch of files or directories into highly compressed archive which are calledtarball
ortar
,bzip
andgzip
in Linux/Unix system.tar Syntax
tar [OPTION...] [FILE]...
Or
tar required Flags
tar {-r|-t|-c|-x|-u}
tar optional Flags
tar {one of the required Flags} [ -d ][-B] [ -F ] [ -E ] [ -i ] [-h ] [ -l ] [ -m ] [ -o ] [ -p ] [ -w] [ -s ] [ -U ] [ -v ] [-Number] [-b Blocks] [-f Archive]
Examples
Create tar Archive File by Compressing an Directory or a Single File
The terminal command below will create a
.tar
file calledsample_dir.tar
with a directory/home/codebind/sample_dir
orsample_dir
in present working directory.ripon@ripon:~$ tar -cvf sample_dir.tar sample_dir sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output ripon@ripon:~$ ls sample_dir sample_dir.tar
Here’s what those flags (-cvf) actually mean
-c, --create
– create a new archive
-x, --extract, --get
– extract files from an archive
-f, --file ARCHIVE
– use archive file or device ARCHIVECreate
tar.gz
ortgz
Archive File by Compressing an Directory or a Single FileThe terminal command below will create a
.tar.gz
file calledsample_dir.tar.gz
with a directory/home/codebind/sample_dir
orsample_dir
in present working directory.Notice that we have added extra flag -z to the command.Here’s what the flag -z actually mean
-z, --gzip, --gunzip --ungzip
– Compress the archive with gzipripon@ripon:~$ tar -cvzf sample_dir.tar.gz sample_dirsample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output ripon@ripon:~$ ls sample_dir sample_dir.tar.gz
The command bellow will create a .tgz file. One this to notice is tar.gz and tgz both are similar.
ripon@ripon:~$ tar -cvzf sample_dir.tgz sample_dirsample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output ripon@ripon:~$ ls sample_dir sample_dir.tgz
Compressing Multiple Directories or Files at Once
Let’s say, For example we want to compress the
sample_dir
directory, thejava_test
directory, and theabc.py
file to a tar file calledsample_dir.tar.gz
.Run the following command to achieve the goal above.
ripon@ripon:~$ tar -cvzf sample_dir.tar.gz sample_dir java_test abc.py sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output java_test/ java_test/HelloCV.java abc.py ripon@ripon:~$ ls sample_dir java_test abc.py sample_dir.tar.gz
Create
.bzip2
Archive File by Compressing an Directory or a Single Fileripon@ripon:~$ tar -cjvf sample_dir.tar.bz2 sample_dir sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output ripon@ripon:~$
Notice that we have added extra flag
-f
to the command.Here’s what the flag-f
actually mean
-f, --file ARCHIVE
– use archive file or device ARCHIVEExtract
.tar
Archive FileWe can extract or untar the compressed file using the tar command. The command below will extract the contents of
sample_dir.tar
to the present directory.ripon@ripon:~$ tar -xvf sample_dir.tar sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output ripon@ripon:~$
The following command will extract or untar files in specified Directory i.e.
/home/codebind/dir_name
in this case.ripon@ripon:~$ tar -xvf sample_dir.tar -C /home/codebind/dir_name sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output ripon@ripon:~$
we have added extra flag
-C
to the command.Here’s what the flag-C
actually mean
-C, --directory DIR
– change to directory DIR

- 129

- 3,139
-
2Also, to check if zip/unzip are installed, use
zip -v
andunzip -v
.
If installed it will return something likeUnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.
(plus several lines of additional info.
If not installed, it will say something likeThe program 'zip' is currently not installed. You can install it by typing: apt install zip
. – SherylHohman Nov 10 '18 at 14:34
\*
as literal star symbol. Just useunzip *.zip
to make shell expand*
to all files ending in.zip
– Sergiy Kolodyazhnyy Jun 02 '17 at 21:55*
alone didn't work for me. It causedfilename not matched
errors.\*
did the job. – arman_aegit Dec 04 '18 at 20:04apropos zip
from the console for the full list. – Stephen W. Wright May 06 '19 at 16:16*.tgz
files): How to unzip .tgz file using the terminal? – Gabriel Staples Sep 19 '20 at 21:54