ook maar es in cvs kwakken. kan ik um een keer fatsoenlijk maken...
This commit is contained in:
parent
ff1d908255
commit
eb9135dded
1 changed files with 69 additions and 0 deletions
69
list_same/list_same
Executable file
69
list_same/list_same
Executable file
|
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
# Generates a list of files in cur. dir which are actually the same
|
||||
# Compares size and MD5 checksum
|
||||
# Handy for cleaning up pictures like this:
|
||||
# list_same|cut -f 1 -d " "|xargs rm
|
||||
|
||||
# This still sucks big time!
|
||||
# Can it handle directories at all?
|
||||
# Why does it bother with calculating md5 checksums of everything,
|
||||
# instead of just the files that have the same size?
|
||||
|
||||
# Changelog:
|
||||
# 2001-08-29:
|
||||
# use MD5; instead of a shell call to md5
|
||||
# some cleaning of code
|
||||
|
||||
use MD5;
|
||||
|
||||
opendir(DIR, ".") or die "can't open . $!";
|
||||
while (defined($file = readdir(DIR))) {
|
||||
&get_finfo;
|
||||
}
|
||||
closedir(DIR);
|
||||
|
||||
$old_md5="";
|
||||
$old_size="";
|
||||
$old_name="";
|
||||
|
||||
foreach $line (sort(@file_lijstje)) {
|
||||
# print $line;
|
||||
$line .= "\n";
|
||||
$line =~ /(.*?)\s(.*?)\s(.*)/;
|
||||
$md5 = $1; $size = $2; $name = $3;
|
||||
if (($old_md5 eq $md5) && ($old_size eq $size)) {
|
||||
print "$old_name $name\n";
|
||||
} else {
|
||||
$old_md5=$md5;
|
||||
$old_size=$size;
|
||||
$old_name=$name;
|
||||
}
|
||||
}
|
||||
|
||||
#################################
|
||||
# dain bread functions
|
||||
|
||||
sub get_finfo() {
|
||||
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks);
|
||||
my $line;
|
||||
if (($file ne ".")&&($file ne "..")) {
|
||||
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
||||
$atime,$mtime,$ctime,$blksize,$blocks) = stat $file;
|
||||
$line = &calc_md5($file);
|
||||
push @file_lijstje, "$line $size $file";
|
||||
}
|
||||
}
|
||||
|
||||
sub calc_md5($file) {
|
||||
my ($file, $digest);
|
||||
$file = shift;
|
||||
$md5 = new MD5;
|
||||
open FILE, "<$file" or die "couldn't open file: $!\n";
|
||||
seek(FILE, 0, 0);
|
||||
$md5->reset;
|
||||
$md5->addfile(FILE);
|
||||
$digest = $md5->hexdigest;
|
||||
close(FILE);
|
||||
return $digest;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue