How to unzip a zip File from the Terminal

How to unzip a zip File from the Terminal

To unzip a compressed zip file Linux command line can be used. Like zip commands, the unzip command in Linux is incredibly versatile and useful for much more than just extracting zip files.  Files from a ZIP archive, which are typically found on MS-DOS computers, can be listed, checked, or extracted using Unzip. The default behavior, or extracting all files from the given ZIP archive into the current file and all subdirectories underneath it, will occur if no settings are provided.


On Linux, how do I install unzip?

Most Linux distributions do not come with unzip installed by default, but you may quickly install it by using the package manager.


Install unzip on Debian and Ubuntu.


$ sudo apt install unzip


Set up unzip on Fedora and CentOS.


$ sudo yum install unzip


What is the Linux unzip syntax?

Once every packet has been installed, use the following terminal command to extract the archive files:


$ unzip


7z is a more practical utility that can be used to zip and unzip several compression formats, including lzma, which is typically the protocol with the highest compression rates.


$ sudo apt-get install p7zip-full


How can I use Linux to extract a zip file?

Locate the zip file by opening the Files app and going to the directory.

Find the file that has to be unzipped.

The context menu with the list of options will show up when you right-click on the file.

To extract files into the current working directory, select “Extract Here.” Alternatively, select “Extract to…” to extract files to a different directory.


In Linux, unzip the arguments

The following is a list of some of the arguments that unzip uses most frequently:


  1. a file ending


It provides the zip archive’s path. The operating system determines the sequence in which each matched file is handled (or file system) when a wildcard is used in the file specification. Only the filename can function as a wildcard; the path cannot.


  1. [File(s)]


A list of archive members to process that can be optional, delimited by spaces. (VMS versions that have VMSCLI selected during compilation were required to use commas to separate files. (For additional details, go to -v in the section below that enumerates your options.) Regular expressions, often known as wildcards, can be used to match multiple members.


  1. [-x xfile(s)]


An optional list of archive members to be omitted from processing. Because wildcard characters frequently match (‘/’) directory separators, you can use this option to exclude any files that are in subdirectories (for exceptions see the option -W).


  1. [-d exdir]


Files will be extracted to the target directory exdir if supplied. By default, all files and subdirectories are recreated in the current directory; the -d option allows extraction in an arbitrary directory (always provided one has permission to write to the current working directory). This option need not occur at the end of the command line; it is also allowed before the zip file specification (with the regular parameters), directly after the zip file path, or between the file(s) and the -x option.


Linux unzip commands and options

You do not need to add any parameters, similar to the zip command, in order to unzip a file. The default practice of unzip is to always ask for permission before erasing existing files. You can extract each letter from the archive using unzip. Unzip into the current directory and any subdirectories beneath it after creating any appropriate subdirectories. Unzip utilizes and accepts the following arguments and commands:


  1. Extract a file into a new directory.


Use the -D (Directory) Option to unzip a ZIP file to a directory other than the current folder. To unzip a zip file, navigate to the file manager and click on the desired file. Launch the terminal window now, and type the following command into it:


$ unzip -d /path/to/directory


  1. Extract tar, tar.gz, and tgz files to a designated directory.


The tar format is used to compress the majority of Linux files. A tarball, also referred to as a collection of uncompressed files, is a.tar file. Because tar doesn’t compress anything, compression needs to be done with a different program. You can make and decompress tar archive files with the tar command. This method also works with additional file formats and kinds. Employing the tar utilityA tar.tar file combined with a gz file is called a tar.gz file. The tar command extracts files to your current directory by default. Enter the following command in the terminal window:


$ tar -xf file-name.tar -C /path/to/directory


Tar is instructed to extract the files with the -x parameter. Additionally, you can use xargs and tar to construct a tar.gz archive and add files from the find command to it. Note: A tool for handling tar.gz files without using the command line is included in certain graphical user interfaces. Using the graphical user interface can be a little challenging.


  1. Open a zip file that is password-protected.


When using the unzip command with the -P option, that is, the -P (Password) Option followed by the password, you can extract a password-protected file:


$ unzip -P PasswOrd


  1. When extracting a ZIP file, remove certain files.


The -X (Exclude) option in the terminal can be used to prevent certain files or directories from being extracted:


$ unzip -x file1-to-exclude file2-to-exclude


  1. Turn off the unzip command’s output


Unzip prints the names of all the files it is extracting by default, along with a summary once the extraction is finished. To prevent these messages from printing, use the -q flag.


$ unzip -q


  1. Replace current files


The -o option can be used to overwrite existing files without asking permission. Open a terminal window, then type the following command to execute the -o (overwrite) option:


$ unzip -o


  1. Extract a zip file without erasing pre-existing data.


The -n option can be used to run this command, forcing unzip to forego extracting an existing file:


$ unzip -n


  1. Give a zip file’s contents a list


The -l (list archive) option is used to list the contents of a specified zip file. Open the Windows terminal and enter the following command to run the current file with the -l option enabled:


$ unzip -l


How to Use the Terminal to Unzip Files—Only on Mac

An application called Terminal offers text-based operating system access.  In contrast to the mainly graphical aspect of the user experience of OS X, terminal provides a command line interface that connects to the operating system. 




On your Mac, Terminal may be found in the Utilities folder inside the Applications folder.  You may also search for Terminal using OSX’s built-in search feature, which is found in the upper right corner of the Finder, or by utilizing the search bar in the upper center of the screen, which is accessible from your launchpad.


Step 1:Move file to the desktop

It will be simpler to locate your file if you move it to the desktop.


Step 2: Launch the Terminal

You may search for Terminal in your Mac by clicking on the magnifying glass icon in the upper right corner or locate it in the Utilities folder, which is in the Applications folder. Moreover, you can use the Launchpad on your Mac to look for Terminal. 


Step 3: Switch to the Desktop Directory

Open a terminal window and enter the following commands: 


(Type commands are shown in bold.)


To change the directory to the desktop, use this.


Step 4: Extract the file type


 unzip {name of your zipped file}.zip


After that, a few lines of code will appear in Terminal to show that your zip file has been unzipped and that the files inside the folder should now be visible on your desktop.


How can I use the terminal on Ubuntu to unzip a zip file?

You can launch a terminal window by either picking the “open in PuTTY” option in the command box located at the left of your screen or by hitting Ctrl + Alt + T.

After doing that, WinSCP will display your username, which you initially supplied to establish a connection.

You now have to enter your password. You can quickly retrieve your password by going back to your server details if you forget it.

Once you have your password copied, return to the terminal window.

After pasting the password with a right-click, press Enter.

You will now be able to access your server over SSH.

The unzip command is installed on your system by default; but, if it isn’t, you can install it with the following command:

apt install unzip $ sudo

After entering it, press Enter, and your server will start installing “unzip.” 

You can now use the following command to unzip your file after installing that:


$ unzip [FileName].zip


You can hit Enter to start your server unzipping the file after you have entered the command and changed “file name” with the name of your zip file.

Check to see whether it has been finished now.

Refreshing your service directory will allow you to see all of the files you have unzipped.

Right now. The following command can be used to relocate the unzipped files and modify the directory:


$ cd [Directory-Name]


How can you unzip a zip file on an Ubuntu Linux machine in a separate directory?

The syntax you should use to unzip a file in a separate directory is as follows:


$ unzip [FileName].zip -d /[Directory-Path]


A collection of files and their descriptions are included in a zip file. Such a file has all the information about each enclosure when you unzip it. You can use the “-q” flag in the syntax above to prevent this:


$ unzip -q [FileName].zip


During the unzipping process, you may also choose to extract just the files you require and leave the rest out. You can accomplish this by using the “-x” flag in the syntax above, taking into account the spaces between the file names:


$ unzip [FileName].zip -x “*Filename1*” “*Filename2*”


How do you unzip a zip file on your computer without overwriting existing files?

Utilizing the “-n” parameter in the command line will prevent you from overwriting files that have already been extracted:


$ unzip -n [FileName].zip


How can several files in a directory be unzipped?

Use the following command to unzip all of the files in a directory:


$ unzip ‘*.zip’


How can I find out how many zip files are in a directory?

To determine how many zip files are contained in a single directory, enter the following command:


$ ls [directory_name]


How can I use the GUI to unzip a zip file on Ubuntu?

On an Ubuntu system, you don’t necessarily need to use the shell to unzip a file. You can complete this task via the graphical user interface (GUI) on the GNOME desktop by doing the following steps:


Launch the file manager.

Navigate to the folder containing your zip file.

On the file, do a right-click.

Choose the “extract here” menu item.

Additionally, there is a “extract to” option that enables you choose the folder in which you wish to extract the data.


How can I zip more than one file on Ubuntu?

On an Ubuntu server, you should combine all of the files into a single zip folder in order to zip numerous files. Then, you ought to do the following actions:


Launch the SSH terminal.

Use the following command to install “zip”: $ apt install zip


Press Enter.

“zip” will now start to install on your server.

After doing that, you can use the zip command:

$ zip [FileName] –r zip.the [FolderName] in zip


The name of the new file you are creating is what we mean when we say “zip File Name.”

The folder you wish to zip is what we mean when we say “Folder Name.”

Press Enter after typing the aforementioned instruction.

Your server will now start to zip the file that you specified in the command.


In brief

An very useful and simple tool for sharing compressed data across a network or even between operating systems is the unzip software. With the help of the unzip command and the tutorial above, you can quickly unzip files on Linux systems using the command line.


Use which unzip to see if your system already has the unzip command installed, and then execute:


$ sudo aptinstall unzip


If you wish to extract to a specific target folder after installing the unzip tool, you can use:


$ unzip -d destination_folder


You may easily do the following to extract to a directory that shares the same name as the zip file in your current working directory:


$ unzip


Leave a Reply

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