Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to unzip all zipped files in a Linux directory?
The unzip command is a Linux utility used to extract compressed files from ZIP archives. When working with multiple ZIP files in a directory, you can extract them all at once using wildcard patterns and command-line options.
Installing Unzip
By default, the unzip utility is not present on most Linux distributions. You can install it using the package manager for your distribution.
For Ubuntu and Debian
sudo apt install unzip
For CentOS and Fedora
sudo yum install unzip
Basic Syntax
unzip file.zip
In the above syntax, replace file.zip with the name of the ZIP file you want to extract.
Unzipping All ZIP Files in a Directory
To extract all ZIP files in the current directory simultaneously, use the wildcard pattern with the unzip command:
unzip "*.zip"
Example Directory
Consider a directory named direct1 containing multiple ZIP files and other content:
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 you can see, there are two ZIP files: zipContent.zip and newZip.zip. Running the unzip command with wildcard will extract both files.
Command Output
After running unzip "*.zip", all ZIP files are extracted and their contents appear in the directory:
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
Additional Options
You can use additional options with the unzip command for better control:
| Option | Description |
|---|---|
-q |
Quiet mode − suppress output messages |
-o |
Overwrite existing files without prompting |
-d directory |
Extract files to specified directory |
-j |
Flatten directory structure (extract to current directory) |
Conclusion
Using unzip "*.zip" is an efficient way to extract all ZIP files in a Linux directory at once. The wildcard pattern automatically matches all files with the .zip extension, saving time when dealing with multiple archives. Remember to use quotes around the wildcard to prevent shell expansion issues.
