Unzip All Files In Subfolders Linux ~upd~ May 2026

chmod -R u+rw . Use -o (overwrite) or -n (never overwrite) to skip prompts. Too many arguments error with for zipfile in $(find ...) The for loop splits output. Use find ... -exec or xargs instead. 12. Alternative Tools unar (from The Unarchiver) Recursive extraction built-in:

find . -name "*.zip" -exec unzip -o {} '*.txt' -d "$(dirname {})" \; Or to extract multiple extensions:

find . -name "*.zip" -exec sh -c 'mkdir -p "$0%.zip"; unzip -o "$0" -d "$0%.zip"' {} \; "unzip: command not found" Install unzip as shown in section 2. "warning: filename contains spaces" Use the null-separated versions ( -print0 + read -d '' or xargs -0 ). "caution: zipfile not a zip archive" Some files may have a .zip extension but not be valid zip files. Use file command to verify: unzip all files in subfolders linux

find . -name "*.zip" -exec unzip -o {} '*.txt' '*.jpg' -d "$(dirname {})" \; This extracts only matching files from each archive, ignoring everything else. Running your command twice will cause unzip to prompt for overwrite (or automatically overwrite with -o ), wasting time. To skip already-unzipped files: Option A: Use -n (never overwrite) find . -name "*.zip" -exec sh -c 'unzip -n "$0" -d "$(dirname "$0")"' {} \; Option B: Check for a marker file (e.g., .unzipped ) find . -name "*.zip" | while read zipfile; do marker="$zipfile.done" if [ ! -f "$marker" ]; then unzip -o "$zipfile" -d "$(dirname "$zipfile")" && touch "$marker" fi done Option C: Remove zip after successful extraction (dangerous but efficient) find . -name "*.zip" -exec sh -c 'unzip -o "$0" -d "$(dirname "$0")" && rm "$0"' {} \; 10. One-Liner Summary for Your Cheatsheet Here is the copy-paste-ready command that handles spaces, extracts in place, and overwrites silently:

find . -name "*.zip" -print0 | while IFS= read -r -d '' file; do unzip -o "$file" -d "$(dirname "$file")" done This is slower than xargs but the most robust. Sometimes you want to extract only .txt or .jpg files from all zip archives in subfolders. chmod -R u+rw

project/ ├── data1/ │ ├── images.zip │ └── notes.zip ├── data2/ │ ├── backup.zip │ └── docs/ │ └── archive.zip └── scripts/ └── source.zip You want to extract each .zip file . For example, images.zip should be extracted inside data1/ , not in the root project/ .

sudo apt install unar unar -o . -f "**/*.zip" # Not as flexible as find find . -name "*.zip" -exec 7z x -o"$(dirname {})" {} -y \; zipinfo (to preview contents without extracting) find . -name "*.zip" -exec zipinfo {} \; 13. Conclusion 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. Use find

$ find . -name "*.zip" -exec sh -c 'unzip -o "$0" -d "$0%/*"' {} \; Archive: ./data1/images.zip inflating: ./data1/photo1.jpg inflating: ./data1/photo2.jpg This is the in production scripts. 4. Method 2: Using a for Loop with find If you prefer readability and more control inside the loop, use a for loop that processes find results.