mkdir -p "$output_dir" echo "$(date): Extracting $zip_path" >> "$LOG_FILE" if unzip -q -o "$zip_path" -d "$output_dir" 2>> "$LOG_FILE"; then echo "✅ $rel_path" else echo "❌ $rel_path (see $LOG_FILE)"
-print0 and -0 : Pair together to separate file names with a null character. This prevents the command from breaking if your folders contain spaces or unusual special characters.
If you prefer a native Bash solution without using the find command, you can use a recursive for loop. This requires enabling the globstar shell option, which allows the ** wildcard to match all files and zero or more directories.
Then, recursively extract :
But be careful – there is no “trash” recovery. Test first. unzip all files in subfolders linux
find . -type f -name "*.zip" -print0 | xargs -0 -I {} sh -c 'unzip -d "$(dirname "{}")" "{}"' Use code with caution.
Always run a first by adding echo before unzip to see which files will be affected without actually extracting them.
Make sure your system has the unzip utility installed. On Debian/Ubuntu:
If you have questions about a specific scenario or need help customizing these commands to your folder structure, I can help . Let's narrow down exactly what you need to achieve! This requires enabling the globstar shell option, which
Use the null-separated versions ( -print0 + read -d '' or xargs -0 ).
For better performance (especially with hundreds of zip files), xargs batches the arguments and reduces the number of unzip processes spawned.
Or with xargs :
The -j flag (junk paths) discards directory structure inside the ZIP. Adjust as needed. unzip all files in subfolders linux
LR-2026-04-12 System Environment: GNU/Linux (Distribution Agnostic) Target Audience: System Administrators, DevOps Engineers, Data Analysts
This is slower than xargs but the most robust.
For more control, such as creating a new folder for each zip's contents to avoid a "file bomb," you can use a loop:
For users who want more control over the loop or want to log what is being extracted, a Bash for loop is an excellent alternative.