To unzip all files in subfolders on Linux, the most efficient method is using the command combined with
. This allows you to traverse directories recursively and process each zip file individually. Method 1: The Command (Recommended)
This is the standard way to handle files across multiple subdirectories. It searches for any file ending in and executes the unzip command on it. find . -name -exec unzip {} -d ./extracted_files/ \; Use code with caution. Copied to clipboard : Starts the search in the current directory. -name "*.zip" : Filters for all ZIP files. -exec unzip {} : Runs the command on each file found. -d ./extracted_files/
: Optional. Specifies a destination directory so your current folders don't get cluttered. Method 2: Using a Simple Bash Loop If you prefer a script-like approach, you can use a
loop. This is useful if you need to perform additional actions (like deleting the zip after extraction). Use code with caution. Copied to clipboard : This globbing pattern requires to be enabled in your shell ( shopt -s globstar ). It looks into every subfolder. unzip all files in subfolders linux
: This part extracts each file into a folder named after the zip file itself. Method 3: Using For a large number of files,
can be faster as it handles the list of files more efficiently. find . -name -print0 | xargs - -I {} unzip {} Use code with caution. Copied to clipboard Key Considerations Permissions : If you encounter "Permission Denied" errors, prepend to your command. Duplicate Names : If multiple zip files contain files with the same name, will ask if you want to overwrite. Use (never overwrite) or (always overwrite) to automate this. Install Unzip
: If the command is missing, install it via your package manager, such as sudo apt install unzip for Ubuntu/Debian. automatically delete the zip files after they are successfully extracted?
How to Unzip and Zip Files on Linux (Desktop and Command Line) To unzip all files in subfolders on Linux,
unzip -l archive.zip
find ... -print0 | while IFS= read -r -d '' zip; do
if ! unzip -q "$zip" -d "$dir"; then
echo "FAILED: $zip" >> /var/log/unzip-errors.log
fi
done
find with xargs (Better for Many Files)When you have thousands of ZIP files, xargs improves performance by batching arguments:
find . -name "*.zip" -type f -print0 | xargs -0 -I {} sh -c 'unzip -o "{}" -d "$(dirname "{}")"'
For large numbers of archives, use GNU parallel or xargs -P: GNU parallel:
export LC_ALL=C
find /path/to/root -type f -iname '*.zip' -print0 |
parallel -0 -j 4 'dir=$(dirname {}); unzip -q {} -d "$dir"'
xargs:
find /path/to/root -type f -iname '*.zip' -print0 |
xargs -0 -n1 -P4 -I{} sh -c 'unzip -q "{}" -d "$(dirname "{}")"'
find (Recommended)This is the safest method because it handles filenames with spaces correctly and works recursively through an unlimited number of nested folders. Dry-run: unzip doesn't support dry-run for extraction; list
The Command:
find . -name '*.zip' -exec unzip {} -d ./output_folder \;
Breakdown:
find .: Start searching in the current directory.-name '*.zip': Look only for files ending in .zip.-exec: Execute the following command on every file found.{}: This is a placeholder that gets replaced by the filename found.-d ./output_folder: Tells unzip to extract files into a specific folder named "output_folder" (change this as needed). Without this, files are extracted exactly where the zip file sits.\;: This signals the end of the command to find.find with -exec (Most Common)The find command is the standard tool for recursively locating files. Combine it with -exec to run unzip on each match.