Unzip All Files In Subfolders Linux =link= -
Combine with --bar for a progress bar:
Then run:
Notes:
find "$SOURCE_DIR" -type f -name "*.zip" -print0 | while IFS= read -r -d '' zipfile; do extract_zip "$zipfile" done
#!/bin/bash # unzip-all.sh - Extract all zip files in all subfolders # Usage: ./unzip-all.sh [target_directory] [--overwrite] [--delete] unzip all files in subfolders linux
While this one-liner is incredibly powerful, understanding how it works—and knowing when to use alternative methods—will save you time and prevent data clutter. In this guide, we will break down the best methods for unzipping files in subfolders, how to handle extracted contents, and how to avoid common pitfalls. The Ultimate One-Liner Explained Method 1: The find + unzip Command (Best for Automation)
If your subfolders or ZIP files contain spaces, standard space-delimited loops will break. The find -exec methods shown in Method 1 handle spaces natively. However, if you are piping outputs, change the delimiter to a null character using -print0 and xargs -0 :
When you need to perform additional logic (e.g., logging, error handling, password prompts), a while loop is your friend:
find . -type f -name "*.zip" -exec unzip -d /target/path/ {} \; Combine with --bar for a progress bar: Then
find . -name "*.zip" -print0 | xargs -0 -I{} unzip -d ./all_extracted "{}"
Always test on a small set of files first, especially when using options like overwrite or delete. With the techniques from this guide, you’ll be able to handle any bulk extraction task on Linux with confidence.
If you work with large archives, you’ve probably faced the need to unzip multiple ZIP files scattered across nested directories. Doing this manually is tedious and error‑prone. Fortunately, Linux provides powerful command‑line tools to automate this task. This article covers everything you need to know about unzipping all files in subfolders on Linux – from basic commands to advanced techniques that handle tricky filenames, preserve directory structures, and even parallelize the process.
find . -name "*.zip" | parallel unzip -d ./extracted/ {} The find -exec methods shown in Method 1
But wait, there's a better way! John recalled that unzip has a -d option to specify the output directory. He wanted to unzip all files into their respective subfolders, without mixing files from different subfolders.
find . -name "*.zip" -print0 | parallel -0 unzip -o {}
This command used find to locate all zip files, and for each file found, it executed unzip with the -d option to unzip the file into a new subfolder named after the original zip file, with _unzip appended to it.
find . -type f -name "*.zip" -print0 | xargs -0 -I {} -P 4 sh -c 'unzip -d "$(dirname "{}")" "{}"' Use code with caution.
