First, enable the globstar shell option to allow recursive directory matching ( ** ):
Use -o (overwrite) or -n (never overwrite) to skip prompts.
-exec ... \; executes the specified command on every file found.
unzip -o {} : Unzip the file. The -o flag existing files without asking (useful for large batches). unzip all files in subfolders linux
If you get a "Permission Denied" error, prepend sudo to the start of the find command. Which one should you use?
find . -name "*.zip" -exec 7z x -o"$(dirname {})" {} -y \;
This public link is valid for 7 days and shares a thread, including any personal information you added. This link or copies made by others cannot be deleted. If you share with third parties, their policies apply. Can’t copy the link right now. Try again later. First, enable the globstar shell option to allow
It automates what would otherwise be a tedious manual task, processing hundreds of files in seconds. 2. Versatility
Use find . -name "*.zip" without the -exec part to see which files will be affected.
echo "Scanning for ZIP files in: $TARGET_DIR" find "$TARGET_DIR" -type f -name "*.zip" -print0 | while IFS= read -r -d '' zipfile; do echo "Extracting: $zipfile" unzip $UNZIP_OPTS -q "$zipfile" -d "$(dirname "$zipfile")" if [[ $? -eq 0 ]]; then echo " -> Success" else echo " -> Failed (check $zipfile)" >&2 fi done unzip -o {} : Unzip the file
By default, unzip will ask you if you want to overwrite files. If you want to automatically say "yes" to everything, add the -o flag: find . -name "*.zip" -exec unzip -o "{}" \; Use code with caution. Summary Table
For repeated use, save this script as unzip-all.sh :
Make it executable:
When keeping original tree intact and extracting into a separate root: