Created
August 9, 2020 14:39
-
-
Save kriansa/b81059c7e2fa1848607a7f0eac6f3008 to your computer and use it in GitHub Desktop.
Make hardlinks out of a list of duplicate files generated by rdfind
This file contains hidden or 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 | |
help() { | |
echo "Makes hardlinks out of a list of duplicates files generated by rdfind." | |
echo | |
echo "usage: $0 <duplicates_file>" | |
} | |
main() { | |
local duplicates_file=$1 | |
if [ $# -lt 1 ]; then | |
help | |
exit 1 | |
fi | |
while read -r line; do | |
# If line is blank, stop the current and start a new one | |
if [ "$line" = "" ]; then | |
origin="" | |
elif [ "$origin" = "" ]; then | |
echo "Origin: $line" | |
origin="$line" | |
else | |
rm "$line" | |
ln "$origin" "$line" | |
echo " Linked to: $line" | |
fi | |
done <"$duplicates_file" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment