Ubuntu: How to Unzip a File using Terminal


If you have a .zip file on your Ubuntu system and you are wondering how to unzip the file using the Terminal (Command Line), well you can make use of the unzip binary.

First thing we need to check if unzip is installed on your Ubuntu system by just typing unzip on on the Terminal Prompt.

# unzip

bash: unzip command not found.

If you get the command not found, well you need to get it installed (this will be the case if you are using a docker image of Ubuntu).

To download and install unzip we will need to make use of the apt-get package manager.

sudo apt-get install unzip

Installation logs:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  zip
The following NEW packages will be installed:
  unzip
0 upgraded, 1 newly installed, 0 to remove, and 0 not upgraded.
Need to get 171 kB of archives.
After this operation, 360 kB of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 unzip arm64 6.0-26ubuntu3.1 [171 kB]
Fetched 171 kB in 1s (179 kB/s) 
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package unzip.
(Reading database ... 4457 files and directories currently installed.)
Preparing to unpack .../unzip_6.0-26ubuntu3.1_arm64.deb ...
Unpacking unzip (6.0-26ubuntu3.1) ...
Setting up unzip (6.0-26ubuntu3.1) ...

Now we are good to unzip our zip file.

unzip my_zip_file.zip

Note this will extract the contents of the zip file in the current directory.

If you wish to unzip the contents to a specific location then you can make use of the -d parameter.

Example:
unzip my_zip_file.zip -d path/to/the/destination/directory

The best way to know more about the utility is by using the unzip -hh option

root@adf079f415ef:/# unzip -hh

Extended Help for UnZip

See the UnZip Manual for more detailed help


UnZip lists and extracts files in zip archives.  The default action is to
extract zipfile entries to the current directory, creating directories as
needed.  With appropriate options, UnZip lists the contents of archives
instead.

Basic unzip command line:
  unzip [-Z] options archive[.zip] [file ...] [-x xfile ...] [-d exdir]

Some examples:
  unzip -l foo.zip        - list files in short format in archive foo.zip

  unzip -t foo            - test the files in archive foo

  unzip -Z foo            - list files using more detailed zipinfo format

  unzip foo               - unzip the contents of foo in current dir

  unzip -a foo            - unzip foo and convert text files to local OS

....
FlagDescription
-ZSwitch to zipinfo mode. Must be the first option.
-hhDisplay extended help.
-APrint extended help for DLL (OS/2, Unix DLL).
-cExtract files to stdout/screen. Includes names. EBCDIC conversions are done if needed.
-fFreshen by extracting only if the file on disk is older.
-lList files using short form.
-pExtract files to pipe (stdout). Only file data is output in binary mode.
-tTest archive files.
-TSet timestamp on archive(s) to that of the newest file.
-uUpdate existing older files on disk as well as extract new files.
-vUse verbose list format. Can also be used to show version information.
-zDisplay only the archive comment.
-aConvert text files to the local OS format. Handles line ends, EOF marker, and EBCDIC character set conversions.
-bTreat all files as binary.
-CUse case-insensitive matching.
-DSkip restoration of timestamps for extracted directories.
-jJunk paths and deposit all files in the extraction directory.
-LConvert uppercase-only names to lowercase.
-nNever overwrite existing files. Skip extracting that file without prompt.
-oOverwrite existing files without prompting.
-qPerform operations quietly. The more q (as in -qq), the quieter.
-sConvert spaces in filenames to underscores.
-UShow non-local characters as ASCII text escapes.
-VRetain VMS file version numbers.
-WModify pattern matching to allow matching at specific directory levels.
-XRestore UICs and ACL entries under VMS, or UIDs/GIDs under Unix, or ACLs under certain operating systems.
-YTreat archived name endings of .nnn as VMS version numbers.
-$Restore volume label if the extraction medium is removable.
-/ eUse e as the extension list.
-^Allow control characters in names of extracted entries.
-2Force unconditional conversion of names to ODS-compatible names (VMS).

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap