Skip to content

Instantly share code, notes, and snippets.

@timabell
Last active June 9, 2025 20:09
Show Gist options
  • Save timabell/f7f776c7f0792ea13ef44798082b9935 to your computer and use it in GitHub Desktop.
Save timabell/f7f776c7f0792ea13ef44798082b9935 to your computer and use it in GitHub Desktop.
AWOL file (hash) finder - compare two hash files, find what's gone missing
#!/bin/sh
# AWOL file (hash) finder - compare two hash files, find what's gone missing
# https://gist.github.com/timabell/f7f776c7f0792ea13ef44798082b9935
# https://github.com/timabell/md5-tools binary must be on the path
# https://github.com/timabell/paths2html binary must be on the path
set -e
# Display help message
show_help() {
echo "Usage: $(basename "$0") <before_hash_file> <after_hash_file>"
echo ""
echo "Compares two hash files and finds files that are missing in the second file."
echo "Parameters:"
echo " before_hash_file Path to the first hash file"
echo " after_hash_file Path to the second hash file"
exit 1
}
# Check if both parameters are provided
if [ $# -ne 2 ]; then
show_help
fi
before=$1
after=$2
# Check if files exist
if [ ! -f "$before" ]; then
echo "Error: File '$before' does not exist." >&2
show_help
fi
if [ ! -f "$after" ]; then
echo "Error: File '$after' does not exist." >&2
show_help
fi
tmp_dir=$(mktemp -d -t verify-XXXXXXXXXX)
echo "Temp folder $tmp_dir" >&2
missing_hashes_file="$tmp_dir/awol-files.txt"
missing_hashes_html_file="$tmp_dir/awol-files.html"
echo "## Looking hashes in $before that have gone AWOL in $after ..." >&2
md5-diff "$before" "$after" | grep --regexp '^\+A' | sed 's/^\+A //' | tee "$missing_hashes_file"
cat "$missing_hashes_file" | awk '{print substr($0, index($0, $2))}' | paths2html > "$missing_hashes_html_file"
xdg-open "$missing_hashes_html_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment