The find command is the standard way to traverse directories in Linux. By combining it with the -exec flag, you can trigger the unzip command for every match found. find . -name "*.zip" -exec unzip {} \; Use code with caution. How it works: . : Starts the search in the current directory. -name "*.zip" : Looks for any file ending in .zip .
data1/ ├── images.zip └── images/ # extracted contents go here ├── photo1.jpg └── photo2.jpg
Use this snippet as a reliable, reusable tool in your Linux administration arsenal. Whether you're managing a multi-terabyte media server or cleaning up a messy download folder, you now have the knowledge to unzip every archive exactly where it belongs.
-d "$(dirname "{}")" extracts the contents into the directory containing that specific ZIP file. Extracting All Files into a Single Target Directory unzip all files in subfolders linux
Sometimes you have zip files inside zip files. The above methods only unzip one level deep. To handle recursive zips, you can use a while loop that keeps looking for files until none are left.
Remember to always handle filenames with spaces (use -print0 + xargs -0 or quoting), decide whether you need to preserve or flatten directory structures, and test destructive operations (like auto‑deleting ZIPs) on a copy first.
find . -name "*.zip" -exec unzip -o "{}" \; The find command is the standard way to
find . -name "*.zip" -print
-exec ... \; executes the specified command on every file found.
find /target/parent -type f -name "*.zip" -execdir sh -c 'unzip -qo "$1" && rm -f "$1"' _ {} \; -name "*
find . -type f -name "*.zip" -exec sh -c 'unzip -d "$(dirname "$1")" "$1" && rm "$1"' _ {} \;
data/ ├── projectA/ │ ├── images.zip │ ├── image1.png (extracted) │ ├── image2.png │ └── notes.txt ├── projectB/ │ ├── backup.zip │ └── data.csv (extracted) └── archive.zip ├── readme.txt (extracted in data/) └── script.sh
This public link is valid for 7 days and shares a thread, including any personal information you added. This link or copies made by others cannot be deleted. If you share with third parties, their policies apply. Can’t copy the link right now. Try again later.
Recursively unzipping all files in subfolders is a common but non-trivial task on Linux. The unzip command lacks native recursion, but combined with find , shell parameter expansion, and careful handling of special characters, you can automate the process cleanly.
The find -execdir unzip pattern is the most reliable, portable, and efficient method to unzip all files in subfolders on Linux. It handles deep nesting, preserves directory structure, and integrates seamlessly into automation scripts. For very large batches, parallel execution with GNU Parallel offers linear speedup.