Re: fdupes and hardlinking duplicate files
On Fri, Dec 17, 2004 at 07:30:24AM -0800, hcheney wrote:
> I have a rather large collection of files and there is a great deal of
> duplication in the tree. What I would like to do is replace all of the
> identical files with hardlinks - which I can't seem to do with fdupes.
Here's another way to do it which should work with any filenames (unless they
contain newlines - hopefully you don't have any of those!).
#!/bin/sh
fdupes -r . "$@" | tee /tmp/fdupes.out |
perl -ne '
chomp;
if (/./) { push @f, $_; }
else {
$k = shift @f;
for (@f) {
chmod 0666, $_; unlink $_; link $k, $_;
}
@f = ();
}
'
THIS SCRIPT IS SUPPLIED WITH ABSOLUTELY NO WARRANTY! WHEN IT LINKS ALL YOUR
FILES TOGETHER INTO ONE BIG MESSY LUMP, DON'T SAY I DIDN'T WARN YOU!
i.e. it should work, but test it first.
Reply to: