Skip to content

Instantly share code, notes, and snippets.

@MaxAtoms
Created March 19, 2023 00:38
Show Gist options
  • Save MaxAtoms/adb1a103726545c84d591b7be5eec134 to your computer and use it in GitHub Desktop.
Save MaxAtoms/adb1a103726545c84d591b7be5eec134 to your computer and use it in GitHub Desktop.
Removes duplicate files in the current working directory when their hash matches exactly
#!/bin/bash
declare -A file_hashes
for file in *; do
if [[ -f $file ]]; then
hash=$(sha256sum "$file" | awk '{print $1}')
if [[ ${file_hashes[$hash]} ]]; then
echo "Deleting duplicate file: $file"
rm -i "$file"
else
file_hashes[$hash]=1
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment