Unzip Files in Linux - How to perform it ?

This article covers how to use the unzip command on the CentOS 8 Linux system.

Also, you will learn various uses of the unzip command through which you can list ZIP archive content and extract files. You can utilize the unzip command according to your needs.

How to Create a ZIP File with the zip Command ?

To create a ZIP file, you need to tell zip the name of the archive file and which files to include in it. 

You don't need to add the ".zip" extension to the archive name, but it does no harm if you do.

To create a file called source_code.zip containing all the C source code files and header files in the current directory, you would use this command:

$ zip source_code *.c *.h

How to Unzip a ZIP File With the unzip Command ?

To extract the files from a ZIP file, use the unzip command, and provide the name of the ZIP file. 

Note that you do need to provide the ".zip" extension.

$ unzip source_code.zip

To Unzip on the Linux command line:

The simplest option that will extract the contents to current directory:

$ unzip backup.zip

To change the target directory for extracted material, use -d option followed by the desired directory:

$ unzip backup.zip -d ./restore-directory

To preview contents of zip file:

$ unzip -l backup.zip

If you don't want to unzip the whole file, then add the specific files to extract at the end:

$ unzip backup.zip file1 subdirectory/file2

The inverse of the above command. Unzip every file EXCEPT the ones specified after the -x modifier:

$ unzip backup.zip -x file1 subdirectory/file2

Unzipping a password protected file:

$ unzip -p mypassword backup.zip