#!/usr/bin/perl -w use File::Find; my %files; find(\&todo, "."); sub todo { my $wd = `pwd`; chomp($wd); my @lst = lstat; if((-f) # normal file && (not -l) # and not a symbolic link && ($lst[3] == 1) # number of hard links == 1 && ($lst[7] > 0) # size > 0 ) { $_ =~ s/\'/\'\\\'\'/g; print "file: \'$_\'\n"; my @md5sum = `md5sum \'$_\'`; $md5sum = $md5sum[0]; chomp $md5sum; $md5sum =~ s/(.{32}).*/$1/; cont: if(exists $files{$md5sum}) { if(system "cmp -s \'$files{$md5sum}[0]->{'name'}\' \'$_\'") { $md5sum = $md5sum . "_"; goto cont; } } my %tmp; $tmp{'path'} = $wd; $tmp{'file'} = $_; $tmp{'name'} = $wd. "/" .$_; push @{$files{$md5sum}}, \%tmp; } } foreach(keys %files) { if($#{$files{$_}}) { my $num = $#{$files{$_}} + 1; my $file_1 = ${$files{$_}}[-1]->{'name'}; my $container_dir = "/cygdrive/r/prjshare/fo00bc/container/$_"; my $container = "$container_dir/${$files{$_}}[-1]->{'file'}"; print("\n\n# +++ file: \"$file_1\" exists $num times\n"); print("mkdir -p \'$container_dir\'\n"); print("\n# bewege\"$file_1\" in container\n\n"); print("mv \'$file_1\' \'$container\'\n"); foreach(@{$files{$_}}) { print "#\tfile: $_->{'name'}\n"; print "rm -f \'$_->{'name'}\'\n"; print "ln -s \'$container\' \'$_->{'name'}\'\n"; } } else { # it's a unique file } }