How to use the Linux Unzip command

Compressing and uncompressing files makes many complicated tasks easier, such as transferring files. In this tutorial we teach you how to use Unzip (unzip), using it to improve your workflow in a .

Zip is a commonly used compression feature that is portable and easy to use. You can even unzip files on Windows that were created on Linux!

Unzip is a utility that is not available in most versions of Linux by default, but can be easily installed. By creating .zip files, you can match file compression!

Here are some scenarios where you might choose to use zip files:

  • If you frequently work between Windows and . The command not only compresses files but is also useful for working with packages of files. It works on multiple operating systems.
  • To save bandwidth. If you have limited or restricted bandwidth, you can use zip between two servers to transfer files.
  • Transfer files quickly. The zip utility reduces the size of the file, thus reducing the transfer time.
  • Upload or download directories faster.
  • Save disk space.
  • Unzip password protected .zip files.
  • Enjoy a good compression ratio.

Remember, before using Unzip on Linux, you will need to have it on your VPS server.

Debian and Ubuntu systems

Installing Unzip is easy! With Ubuntu and Debian, use the following command to install this unzip command:

sudo apt install unzip

Sit back and wait a minute, until the installation is finished.

To create zip files, you will also need to install zip. You can do it with the following command:

sudo apt-get install zip

Install Unzip on Linux CentOS and Fedora

Again, this is simple and can be done with the following command:

sudo yum install unzip

Once the installation is complete, you can verify the path with the following command:

which unzip

After executing said command line, you should get command line similar to this:

/usr/bin/unzip

You can also confirm that everything is installed correctly using the following command. This will give you a breakdown of the command itself and the installed package.

See also  How to use the tar command in Linux

unzip -v

How to use Zip and Unzip on Linux

Now that we know how to install the package using the Unzip command on Linux, we can start learning the basic uses of it:

Create zip files on Linux

The basic syntax to create a .zip file is:

zip options zipfile list_Of_files

To test this, we create two files: ExampleFile.txt Y ExampleFile1.txt. We will compress them into sampleZipFile.zip with the following command:

zip sampleZipFile.zip ExampleFile.txt ExampleFile1.txt

Use the Unzip command on Linux to unzip a file

The Unzip command can be used without any options. This will unzip all the files in the current directory. Let’s look at an example of this:

unzip sampleZipFile.zip

This will by default unzip the file sampleZipFile.zip in the current folder, as long as you have read and write access.

Delete a file from a .zip archive

Once a .zip file is created, you can delete or remove files that are in it. So if you want to remove ExampleFile.txt of the file sampleZipFile.zip existing, you can use the following command:

zip –d sampleZipFile.zip ExampleFile.txt

Once you run this command, you can unzip the .zip file using:

unzip sampleZipFile.zip

Doing so will show that ExampleFile.txt has been removed and is not found in the extract.

How to update zip files

Once a .zip file is created, you can add a new file to an existing .zip file. Suppose you need to add a new file ExampleFile2.txt to the sampleZipFile.zip it already exists. You can do this with the command shown below:

zip –u sampleZipFile.zip ExampleFile2.txt

Now if you extract sampleZipFile.zipyou will see that the new file ExampleFile2.txt has been added.

Move a file to a Zip

You can easily move specific files to a zip file. This means that after the files are added to the zip, they will be removed from their original directories. This is generally used when you have a large file or directory, but need to save disk space. You can do it by adding the option -m. A sample of this command would be:

zip –m sampleZipFile.zip ExampleFile2.txt

See also  WordPress 6.0 Beta: First look at the next version

Recursive use of Zip on Linux

The option -r is used to compress files recursively. This option will compress all the files inside a folder. An example of such a command is shown below:

zip –r sampleZipFile.zip MyDirectory

In the example, MyDirectory is a directory that has multiple files and subdirectories to be compressed.

Exclude files in a Zip

By creating a .zip file, you can exclude unwanted files. This is done using the option -x. Here is an example:

zip -x sampleZipFile.zip ExampleFile.txt

Here ExampleFile.txt will not be added to sampleZipFile.zip.

Unzip a file to a different directory

In case you don’t want to unzip the archive to the current directory but rather want to specify a directory location, this can also be done. Use the option -d to provide a directory path in the Linux Unzip command. An example of such a command is shown below:

unzip sampleZipFile.zip -d /usr/sampleZip/ExampleDir

Using Linux Unzip with multiple Zip files

If you want to unzip multiple existing zip files to your current working directory, you can use the following command:

unzip ‘*.zip’

This command will unzip all the individual zip files.

Suppress output when using Unzip on Linux

By default, when we use the Unzip command, the command prints the list of all files that are extracted. This is a summary of the extraction process. In case you want to suppress these messages, you can use the -q option. The command would be as shown below:

unzip -q sampleZipFile.zip

Exclude files with Unzip on Linux

In case you want to extract all the files except one, you can use the following command:

unzip sampleZipFile.zip -x excludedFile.txt

In this case, the command will unzip all files except excludedFile.txt.

You can also prevent specific file types from being extracted. We give you an example:

unzip sampleZipFile.zip -x “*.png/*”

The above command will exclude all .png files from being extracted.

Using Unzip on Linux with password protected files

A password protected .zip file can be uncompressed with the -P option. An example of such a command is shown below:

See also  Web Pro files

unzip -P Password sampleZipFile.zip

In the above command, Password is the password for the .zip file.

Overwrite zip files

When you unzip the same file more than once to the same location where, by default, a message will appear asking if you want to overwrite current file, overwrite all files, skip extracting current file, skip extracting all files or rename the current file.

The options would be the following:

is o ll one ename

Or you can overwrite all files using the option -either. We show you an example:

unzip -o sampleZipFile.zip

You should be careful when running this command as this will completely overwrite any existing copies. Any changes made to the previous copy will be overwritten.

Use in Linux Unzip without overwriting files

If you unzipped a file and made some changes but accidentally deleted some files that made it up, you can use this alternative to restore it! Use the option -n to skip extracting files that already exist. This will only extract the files that do not exist, therefore the ones that you had accidentally deleted before. An example of this command is:

unzip -n sampleZipFile.zip

How to list the contents of a Zip file in Linux

The option -l lists all the files inside a .zip file, along with the timestamp and other basic details. An example of this command is:

unzip -l sampleZipFile.zip

To end

As you can see, it is very easy to use all the essential functions of the Linux zip and unzip commands. So don’t wait any longer! Start improving your file management right now.

Deyi is a digital marketing enthusiast, with a background in web design, content creation, copywriting, and SEO. She is part of ‘s SEO & Localization team. In her free time, she likes to develop projects, read a book or watch a good movie.

Loading Facebook Comments ...
Loading Disqus Comments ...