Unzip All Files In Subfolders Linux ●
A critical distinction in this process is where the extracted files end up.
Unzipping all files in subfolders on Linux is a perfect example of the command line’s power. With a single find one-liner, you can replace hours of manual clicking. The method you choose depends on your needs:
Practice these commands on a test directory first. Once comfortable, you’ll wonder how you ever managed archives without them. Linux gives you the tools—now you know how to wield them.
Have a unique scenario? The find and unzip man pages (man find, man unzip) offer even deeper customization for timestamps, exclusion patterns, and logging.
How to Unzip All Files in Subfolders on Linux Dealing with nested zip files can be a tedious manual task. Fortunately, Linux provides powerful command-line tools to automate this process in seconds. Whether you need to extract them all into one place or keep them in their original subdirectories, here is how you can get it done. 1. The Simple Solution: Unzip in Current Directory unzip all files in subfolders linux
If you have multiple zip files in your immediate folder and want to extract them all at once, use this command: unzip '*.zip' Use code with caution. Copied to clipboard
Note: The single quotes are essential to prevent the shell from expanding the wildcard before it reaches the unzip command. 2. The Recursive Powerhouse: Using find
To find and unzip files buried deep within subfolders, the find command is your best friend. Option A: Extract All Files "In Place"
This command finds every .zip file and extracts its contents directly into the same subdirectory where the zip file is located. find . -name "*.zip" -execdir unzip -o {} \; Use code with caution. Copied to clipboard -name "*.zip": Finds all files ending in .zip. A critical distinction in this process is where
-execdir: Runs the command from the directory where the file was found. -o: Overwrites existing files without prompting. {}: A placeholder for the current file being processed. Option B: Extract and Create New Folders
If you want to extract each zip into its own folder (named after the zip file) to keep things organized:
find . -name "*.zip" | while read filename; do unzip -o -d "$filename%.*" "$filename"; done Use code with caution. Copied to clipboard
This loop takes each filename, strips the .zip extension, and uses that as the destination directory. 3. Alternative: Using a Bash Function Practice these commands on a test directory first
For a reusable solution, you can add this function to your ~/.bashrc file. This enables a quick alias like ez (extract zips) to handle the recursion for you.
Linux Unzip Command: Extract Zip Files With Examples | Contabo Blog
Use -P (insecure, as password appears in process list) or -p to read from stdin.
Example with find and a stored password (not recommended for production):
find . -name "*.zip" -type f -exec unzip -P 'secret' {} -d {}.dir \;
For interactive password entry, use a loop:
find . -name "*.zip" -type f | while read f; do unzip "$f" -d "$f%.zip_dir"; done
find . -name "*.zip" -exec 7z x -o"$(dirname {})" {} -y \;
find . -name "*.zip" -exec sh -c 'unzip -n "$0" -d "$(dirname "$0")"' {} \;