Created
February 6, 2022 00:58
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