How to unzip all zipped files in a Linux directory?

LinuxOperating SystemOpen Source

Unzip is the Linux command utility that we will use to unzip all zipped files present in a Linux directory.

By default, the unzip utility is not present on most of the Linux distributions and we can install the same with the help of the commands mentioned below.

For Ubuntu and Debian

sudo apt install unzip

For CentOS and Fedora

sudo yum install unzip

Syntax

unzip file.zip

In the above syntax we just need to replace the file.zip with the file that we want to unzip.

Consider a case where I have a directory named direct1 that looks something like this −

immukul@192 direct1 % ls -ltr
total 5216
-rwxrwxrwx 1 immukul staff 446966 Sep 23 1998 wget-1.5.3.tar.gz
drwxr-xr-x 2 immukul staff 64 Jul 13 11:36 dr1
drwxr-xr-x 3 immukul staff 96 Jul 13 11:36 dr2
-rw-r--r-- 1 immukul staff 2201512 Jul 14 09:19 zipContent.zip
-rw-r--r-- 1 immukul staff 122 Jul 14 16:10 somefile.txt
drwxrwxrwx 5 immukul staff 160 Jul 16 10:01 d1
-rwxrwxrwx 1 immukul staff 300 Jul 16 10:06 sample.sh
-rw-r--r-- 1 immukul staff 83 Jul 16 10:58 sample.txt
drwxr-xr-x 3 immukul staff 96 Jul 16 11:05 dir1
drwxr-xr-x 3 immukul staff 96 Jul 16 11:46 dir2
-rw-r--r-- 1 immukul staff 661 Jul 16 11:47 newZip.zip

As one can notice, there are few .zip files present in the above directory and we can unzip all these .zip files with the help of the command shown below.

Command

unzip “*.zip”

Now once we run the following command, all the .zip files will be unzipped and their contents will be printed in the terminal.

Output

immukul@192 direct1 % ls -ltr
total 13504
-rwxrwxrwx 1 immukul staff 446966 Sep 23 1998 wget-1.5.3.tar.gz
-rwxrwxrwx 1 immukul staff 7 Jul 7 10:37 2.txt
-rwxrwxrwx 1 immukul staff 4234901 Jul 7 17:41 file.txt
-rwxrwxrwx 1 immukul staff 8 Jul 8 19:05 3.txt
-rwxrwxrwx 1 immukul staff 946 Jul 12 18:45 sample.sh
drwxr-xr-x 2 immukul staff 64 Jul 13 11:36 dr1
drwxr-xr-x 3 immukul staff 96 Jul 13 11:36 dr2
-rw-r--r-- 1 immukul staff 2201512 Jul 14 09:19 zipContent.zip
-rw-r--r-- 1 immukul staff 122 Jul 14 16:10 somefile.txt
-rw-r--r-- 1 immukul staff 83 Jul 16 10:58 sample.txt
drwxr-xr-x 3 immukul staff 96 Jul 16 11:05 dir1
drwxr-xr-x 3 immukul staff 96 Jul 16 11:46 dir2
-rw-r--r-- 1 immukul staff 661 Jul 16 11:47 newZip.zip
drwxrwxrwx 5 immukul staff 160 Jul 16 11:48 d1
drwxr-xr-x 4 immukul staff 128 Jul 16 11:48 d2
raja
Published on 31-Jul-2021 11:55:13
Advertisements