Skip to content

Instantly share code, notes, and snippets.

@dotysan
Created February 6, 2022 00:58
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 dotysan/51f6067be62688a2136837653375c329 to your computer and use it in GitHub Desktop.
Save dotysan/51f6067be62688a2136837653375c329 to your computer and use it in GitHub Desktop.
Use fdupe to hardlink duplicates
#! /usr/bin/env bash
#
# Use fdupe to hardlink duplicates
#
set -e #x
main() {
echo "BEFORE: $(du -sh .)"
fdupes --recurse --noempty --sameline . |while read -r dupes
do #echo "DUPES: $dupes"
#xargs ls -ltr <<<"$dupes"
xargs ls -tr1 <<<"$dupes" |while read -r dupe
do if [ -z "$first" ]
then first="$dupe"
elif [ -f "$first" -a -f "$dupe" ]
then ln -f "$first" "$dupe"
else
>&2 echo "ERROR: cannot ln \"$first\" \"$dupe\""
exit 1
fi
done
done
echo "AFTER: $(du -sh .)"
}
main
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment