Created
March 19, 2023 00:38
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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