Created
February 6, 2022 00:58
-
-
Save dotysan/51f6067be62688a2136837653375c329 to your computer and use it in GitHub Desktop.
Use fdupe to hardlink duplicates
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
#! /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