Extract files from zip archive in Ubuntu

Zip is an archive file format. A zip file may consist of any number of compressed files and folders. It was developed by Phillip Walter Katz and the file format was first released in the year 1989. At the time of writing the article, the latest version available for the file format is 6.3.5. In this article, we would discuss how to extract files from zip archive in Ubuntu.

To extract files from a zip archive, we would use the command-line utility unzip. Also, following few operations would require to have superuser privileges. In case you don’t have one then contact your System Administrator for assistance.

Install unzip command-line utility in Ubuntu

Although the package comes installed with the default Ubuntu distribution. This is being mentioned just in case you don’t have the package installed. To install unzip command-line utility, run the following in terminal –

sudo apt install unzip

Extract files from zip archive

The extensions used by zip archive is .zip or .ZIP. Also, to identify whether a file is zip archive or not we can use command-line utility file. To do so, run the following in terminal –

file <file-name.zip>

The output should resemble-

<file-name.zip>: Zip archive data, at least v2.0 to extract

Also, we can list all files available in a zip archive. To list the files present in zip archive, run the following in terminal –

unzip -l <file-name.zip>

Thereafter, to extract a valid zip archive in the current directory. Run the following in terminal –

unzip <file-name.zip>

This would extract all the files present in zip archive. But, to extract a specific file from zip archive, first we would get the path of file through –

unzip -l <file-name.zip>

For instance, path of file to be extracted is path/to/file.png. Now, run the following in terminal –

unzip -j <file-name.zip> path/to/file.png

Furthermore, we could extract a zip archive to a specific location. -d option is to be used along with the location where our archive is to be extracted.

unzip <file-name.zip> -d /path/to/directory

For instance, we would want to extract firefox-71.0a1.en-US.win32.zip to Downloads directory. Then, run the following in terminal –

unzip firefox-71.0a1.en-US.win32.zip -d /home/<user-name>/Downloads

If we would like to hide the messages specifying what all files are being extracted in command prompt, then we can use -q option.

unzip -q <file-name.zip> -d /path/to/directory

By default, unzip utility would ask you what to do in case the extracted file already exists. You could choose any of following options accordingly – [y]es, [n]o, [A]ll, [N]one, [r]ename.

In conclusion, we have discussed few of the options available to extract files from a zip archive.

Similar Posts