Skip to content

Instantly share code, notes, and snippets.

@leonirlopes
Forked from apolzek/rmhash.sh
Created March 31, 2022 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonirlopes/46b8e77afa549492c04934c037b296de to your computer and use it in GitHub Desktop.
Save leonirlopes/46b8e77afa549492c04934c037b296de to your computer and use it in GitHub Desktop.
Remove files with the same hash
# by: apolzek
md5sum * | sort -n > .file
filename='.file'
n=1
x=1
while read line; do
current_hash=$(echo $line | awk {'print $1'})
echo "[debugging] current_hash: $current_hash"
x=$(($n + 1))
next_hash=$(awk NR==$(echo $x) .file | awk {'print $1'})
echo "[debugging] next_hash: $next_hash"
if [ -z $next_hash ]; then
echo "[debugging] end"
rm .file
exit
fi
if [ $current_hash == $next_hash ]; then
echo "[debugging] remove duplicate"
first_duplicate_file=$(echo $line | cut -c34-)
echo "[debugging] name first duplicate file: $first_duplicate_file"
second_duplicate_file=$(awk NR==$(echo $x) .file | cut -c35-)
echo "[debugging] name second duplicate file: $second_duplicate_file"
rm "$second_duplicate_file"
fi
echo ""
n=$((n+1))
done < $filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment