-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_symlinks
executable file
·90 lines (74 loc) · 1.89 KB
/
find_symlinks
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
85
86
87
88
89
90
#!/usr/bin/env perl
use File::Find;
my $path = shift or ( print( 'Usage: find_symlinks (path)
Example: find_symlinks /var
') && exit);
if(!-d $path){
print "Please pass a directory.\n";
}
print "Beginning search on $path.
Depending upon how many files you have, this might take a while. Please
be patient.\n\n";
find(
{
'wanted' => \&find_links,
'no_chdir' => 1
}, $path
);
my %files;
my @symlink_files;
my @symlink_dirs;
my $hardlink_files;
my $hardlink_dirs;
sub find_links{
if(-l $_){
push(@symlink_files,$_) if (-f $_);
push(@symlink_dirs,$_) if (-d $_);
}
else{
my ($dev,$ino) = stat($_);
if(-f $_){
push(@{ $hardlink_files{"$dev $ino"} },$_);
}
if(-d $_){
push(@{ $hardlink_dirs{"$dev $ino"} },$_);
}
}
}
print "--------------------------------------\n";
print "Files with multiple hardlinks:\n";
print "--------------------------------------\n\n";
foreach my $key(sort keys %$hardlink_files){
if( scalar(@{ $hardlink_files->{$key} }) ){
print "$key:";
foreach my $file(sort @{ $hardlink_files->{$key} }){
print "\t$file\n";
}
print "\n";
}
}
print "--------------------------------------\n";
print "Directories with multiple hardlinks:\n";
print "--------------------------------------\n\n";
foreach my $key(sort keys %$hardlink_dirs){
if( scalar(@{ $hardlink_dirs->{$key} }) ){
print "$key:";
foreach my $dir(sort @{ $hardlink_dirs->{$key} }){
print "\t$dir\n";
}
print "\n";
}
}
print "--------------------------------------\n";
print "Files that are actually symlinks:\n";
print "--------------------------------------\n\n";
foreach my $file(sort @symlink_files){
print "$file -> ".readlink($file)."\n";
}
print "\n";
print "--------------------------------------\n";
print "Directories that are actually symlinks:\n";
print "--------------------------------------\n\n";
foreach my $dir(sort @symlink_dirs){
print "$dir -> ".readlink($dir)."\n";
}