I have a lot of zip files. Some are not downloaded correctly and are corrupted. I want to remove them.
Is there a way to find the corrupted archives in bash?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The following will print the name of all corrupted zip files in the current directory and its subdirectories:
#!/bin/bash shopt -s dotglob nullglob globstar for file in ./**/*.zip; do [[ -r $file ]] || continue unzip -t "$file" >/dev/null 2>&1 || printf '%s\n' "$file" done
If you wish to remove them, simply replace
printf '%s\n' "$file" with
rm -f "$file".