Skip to content

Instantly share code, notes, and snippets.

@kriansa
Created August 9, 2020 14:39
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 kriansa/b81059c7e2fa1848607a7f0eac6f3008 to your computer and use it in GitHub Desktop.
Save kriansa/b81059c7e2fa1848607a7f0eac6f3008 to your computer and use it in GitHub Desktop.
Make hardlinks out of a list of duplicate files generated by rdfind
#!/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