Media & Document File Corruption Checker Script
Overview
This Bash script is a handy tool for verifying the integrity of common media (images, videos, audio) and document files on Linux systems.
It’s designed for speed, accuracy, and safety, helping you find corrupted files without overloading your CPU.
Whether you’re a photographer with thousands of images, a video editor managing terabytes of footage, or just someone archiving documents — this tool helps keep your files healthy.
Features
○ Supports multiple file types:
Images: .jpg , .jpeg , .png , .gif , .bmp , .tiff , .webp
Videos: .mp4 , .mkv , .mov , .avi , .wmv , .flv , .webm
Audio: .mp3 , .wav , .flac
Documents: .pdf , .docx , .odt
Recursive or single-folder scanning — you decide.
Low CPU load — uses lightweight checks and efficient commands.
Progress display — know exactly how far along the scan is.
○ Accurate verification:
Images checked with identify (ImageMagick)
Videos & audio checked with ffprobe (FFmpeg)
PDFs checked with pdftotext (detects unreadable/encrypted files)
.docx and .odt checked via archive integrity
○ Lists only corrupted files — no unnecessary noise.
Why Use This Script?
File corruption can happen for many reasons:
Faulty hard drives or SSDs
Interrupted downloads
File transfers gone wrong
Damaged archives from old backups
This script ensures you find the bad files before you need them — preventing nasty surprises.
Requirements
You’ll need the following tools installed:
imagemagick , ffmpeg , poppler-utils , unzip
ImageMagick → image checking
FFmpeg → audio/video verification
poppler-utils → pdftotext for PDF scanning
unzip → document archive integrity checks
Here's the script:
corrupted-files-finder.sh:
Copy
#!/usr/bin/env bash
### How To Use
# chmod +x this_script.sh
# ./this_script.sh /path/to/folder yes # recursive (default)
# ./this_script.sh /path/to/folder no # only current directory (--max-depth=1)
#
# NOTE: Monitor system resources (use `htop`, `btop` etc) if run recursively
# ..to avoid system crashes! if the content is too large.
###
# Define supported file types and their categories
declare -A FILE_TYPES=(
[mp3]="audio"
[wav]="audio"
[flac]="audio"
[m4a]="audio"
[wma]="audio"
[mp4]="video"
[mkv]="video"
[mov]="video"
[wav]="video"
[avi]="video"
[wmv]="video"
[flv]="video"
[webm]="video"
[3gp]="video"
[mpg]="video"
[mpeg]="video"
[vob]="video"
[jpg]="image"
[jpeg]="image"
[png]="image"
[gif]="image"
[bmp]="image"
[tiff]="image"
[webp]="image"
[svg]="image"
[pdf]="doc"
[docx]="doc"
[odt]="doc"
)
# Get input arguments
SCAN_PATH="${1:-.}"
RECURSIVE="${2:-yes}"
# Determine maxdepth option for find
if [[ "$RECURSIVE" =~ ^[Yy](es)?$ ]]; then
MAXDEPTH=""
else
MAXDEPTH="-maxdepth 1"
fi
# Check required tools
for tool in identify ffprobe pdftotext unzip file; do
if ! command -v "$tool" >/dev/null 2>&1; then
echo "Error: '$tool' is required but not installed. Please install it and rerun."
exit 1
fi
done
# Count total files before scanning
TOTAL_FILES=0
for ext in "${!FILE_TYPES[@]}"; do
count=$(find "$SCAN_PATH" $MAXDEPTH -type f -iname "*.$ext" | wc -l)
TOTAL_FILES=$((TOTAL_FILES + count))
done
if (( TOTAL_FILES == 0 )); then
echo "No supported files found to scan."
exit 0
fi
echo "Found $TOTAL_FILES files to scan."
echo "Scanning folder: $SCAN_PATH"
echo "Recursive scan: $([[ -z "$MAXDEPTH" ]] && echo yes || echo no)"
echo
check_file() {
local file="$1"
local ext="${file##*.}"
ext="${ext,,}" # convert to lowercase
case "${FILE_TYPES[$ext]}" in
image)
identify "$file" >/dev/null 2>&1
;;
video|audio)
ffprobe -v error -show_format -show_streams "$file" >/dev/null 2>&1
;;
doc)
case "$ext" in
pdf)
pdftotext "$file" - >/dev/null 2>&1
;;
docx|odt)
unzip -tq "$file" >/dev/null 2>&1
;;
*)
file "$file" >/dev/null 2>&1
;;
esac
;;
*)
return 0 # Unknown type, skip
;;
esac
}
CORRUPTED_FILES=()
echo "Starting corruption scan..."
scanned=0
for ext in "${!FILE_TYPES[@]}"; do
while IFS= read -r -d '' file; do
scanned=$((scanned + 1))
printf "\rScanning files: %d/%d" "$scanned" "$TOTAL_FILES"
if ! check_file "$file"; then
CORRUPTED_FILES+=("$file")
fi
done < <(find "$SCAN_PATH" $MAXDEPTH -type f -iname "*.$ext" -print0)
done
echo # newline after progress
echo
if [[ ${#CORRUPTED_FILES[@]} -eq 0 ]]; then
echo "✅ No corrupted files found."
else
echo "⚠️ Corrupted files found:"
for f in "${CORRUPTED_FILES[@]}"; do
echo " $f"
done
fi
👣 Make the file executable:
chmod +x corrupted-files-finder.sh
👣 Run the script...
./corrupted-files-finder.sh /path/to/folder yes
First argument = folder to scan (. for current directory)
Second argument = yes for recursive, no for current folder only
** You can ignore the last yes as the recursive scan is the default behaviour anyway!
Tips
Run it periodically to keep your library healthy.
Use it after transferring or downloading large batches of files.
Lower its priority if you want to scan in the background:
nice -n 19 ./corrupted-files-finder.sh /path/to/folder
💡 Notes:
This script is experimental and should not be considered as the complete solution for detecting the corrupted files. It may be extended in the future to improve its effectiveness.
⚠️ Disclaimer:
This script is provided as-is, without any warranties or guarantees of any kind. Use of this at your own risk.