perl5.001 patch.1f
[p5sagit/p5-mst-13.2.git] / pod / modpods / Find.pod
CommitLineData
a0d0e21e 1=head1 NAME
2
3find - traverse a file tree
4
748a9306 5=head1 SYNOPSIS
a0d0e21e 6
7 use File::Find;
8 find(\&wanted, '/foo','/bar');
9 sub wanted { ... }
10
11=head1 DESCRIPTION
12
748a9306 13The wanted() function does whatever verifications you want. $dir contains
a0d0e21e 14the current directory name, and $_ the current filename within that
15directory. $name contains C<"$dir/$_">. You are chdir()'d to $dir when
16the function is called. The function may set $prune to prune the tree.
17
18This library is primarily for the C<find2perl> tool, which when fed,
19
20 find2perl / -name .nfs\* -mtime +7 \
21 -exec rm -f {} \; -o -fstype nfs -prune
22
23produces something like:
24
25 sub wanted {
26 /^\.nfs.*$/ &&
27 (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
28 int(-M _) > 7 &&
29 unlink($_)
30 ||
31 ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
32 $dev < 0 &&
33 ($prune = 1);
34 }
35
36Set the variable $dont_use_nlink if you're using AFS, since AFS cheats.
37
38Here's another interesting wanted function. It will find all symlinks
39that don't resolve:
40
41 sub wanted {
42 -l && !-e && print "bogus link: $name\n";
43 }
44