Debian Codegraph @

examples/dups3

raw
1 #!perl
2
3 # dups3: simple script for showing duplicate files
4
5 =head1 NAME
6
7 dups3 - Show Duplicate Files
8
9 =head1 SYNOPSIS
10
11 Usage: dups3 files ...
12
13 dups3 is a fast script for discovering duplicate files. It achieves
14 its efficiency by comparing file digests rather than the file
15 contents themselves, the latter being much larger in general.
16
17 The NIST Secure Hash Algorithm 3 (SHA-3) is highly collision
18 resistant, meaning that two files with the same SHA-3 digest have
19 an almost certain probability of being identical.
20
21 The dups3 script works by computing the SHA3-224 digest of each
22 file and looking for matches. The search can reveal more than
23 one set of duplicates, so the output is written as follows:
24
25 match1_file1
26 match1_file2
27 match1_file3
28 etc.
29
30 match2_file1
31 match2_file2
32 etc.
33
34 =head1 AUTHOR
35
36 Mark Shelor <[email protected]>
37
38 =head1 SEE ALSO
39
40 Perl module L<Digest::SHA3>
41
42 =cut
43
44 use strict;
45 use Digest::SHA3;
46
47 die "usage: dups3 files ...\n" unless @ARGV;
48
49 my @files = grep { -f $_ } @ARGV;
50
51 my %dups3;
52 for (@files) {
53 my $digest = Digest::SHA3->new->addfile($_, "b")->hexdigest;
54 push(@{$dups3{$digest}}, $_);
55 }
56
57 for (keys %dups3) {
58 my $ref = $dups3{$_};
59 if (scalar(@$ref) > 1) {
60 print join("\n\t", @$ref), "\n\n";
61 }
62 }