February 2006
Intermediate to advanced
304 pages
6h 16m
English
Symbolic links are nice, but they can be a real pain when they get broken. This script checks a directory tree for symbolic links and makes sure they are good.
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use File::Find ();
6
7 use vars qw/*name *dir *prune/;
8 *name = *File::Find::name;
9 *dir = *File::Find::dir;
10 *prune = *File::Find::prune;
11
12 # Traverse desired filesystems
13 File::Find::find({wanted => \&wanted}, @ARGV);
14 exit;
15
16
17 sub wanted {
18 if (-l $_) {
19 my @stat = stat($_);
20 if ($#stat == -1) {
21 print "Bad link: $name\n";
22 }
23 }
24 }
25
The script takes a directory or set of directories as arguments. It then scans each directory tree and reports ...
Read now
Unlock full access