3 ms·
Here's a quick one if your filesystem supports hard links: #!/bin/ksh typeset -A hashes find . -type f -exec shasum -a 512 {} \; | while
by kruhft 10y ago
Here's a quick one if your filesystem supports hard links:
#!/bin/ksh
typeset -A hashes
find . -type f -exec shasum -a 512 {} \; |
while read hash filename; do
if [[ -z ${hashes[$hash]} ]]; then
hashes[$hash]="$filename"
else
echo ln -f "'${hashes[$hash]}'" "'$filename'"
fi
done
Pipe to /bin/sh if you're happy with the results.
- rsanders 10y agoGood answer, but unless you mark the files read-only/immutable, this ought to have big red flags all over it. Userland just can't do this safely in the general case.
- kruhft 10y agoGood point. This is for data that's not in use.
- khc 10y agoDo you actually use this? Seems at the minimum you want to use -xdev with find and do something better than ln -f.
- kruhft 10y agoYes, I forgot to put in -xdev, but what's wrong with ln -f?