-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathfdf-attr
84 lines (68 loc) · 1.71 KB
/
fdf-attr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/perl
# Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 22 January 2012
# https://github.com/trizen
# Find files which have the same attributes
#
## WARNING! For strict duplicates, use the 'fdf' script:
# https://github.com/trizen/perl-scripts/blob/master/Finders/fdf
#
use 5.005;
use strict;
use warnings;
use File::Find qw(find);
use Getopt::Std qw(getopts);
my @dirs = grep { -d } @ARGV;
die <<"HELP" if !@dirs;
usage: $0 [options] /my/path [...]
Options:
-f : keep only the first duplicated file
-l : keep only the last duplicated file
HELP
my %opts;
if (@ARGV) {
getopts("fl", \%opts);
}
sub find_duplicated_files (&@) {
my $code = shift;
my %files;
find {
no_chdir => 1,
wanted => sub {
lstat;
return if ((-s _) < 4 * 1024); # skip files smaller than 4KB
(-f _)
&& (not -l _)
&& push @{
$files{
join($;,
(-r _), (-w _), (-x _), (-o _), (-R _), (-W _),
(-X _), (-O _), (-s _), (-u _), (-g _), (-k _),
)
}
},
$_;
}
} => @_;
foreach my $files (values %files) {
next if $#{$files} < 1;
$code->(@{$files});
}
return;
}
{
local $, = "\n";
local $\ = "\n";
find_duplicated_files {
print @_, "-" x 80 if @_;
foreach my $i (
$opts{f} ? (1 .. $#_)
: $opts{l} ? (0 .. $#_ - 1)
: ()
) {
unlink $_[$i] or warn "[error]: Can't delete: $!\n";
}
}
@dirs;
}