Commit | Line | Data |
a0d0e21e |
1 | =head1 NAME |
2 | |
3 | find - 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 |
13 | The wanted() function does whatever verifications you want. $dir contains |
a0d0e21e |
14 | the current directory name, and $_ the current filename within that |
15 | directory. $name contains C<"$dir/$_">. You are chdir()'d to $dir when |
16 | the function is called. The function may set $prune to prune the tree. |
17 | |
18 | This 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 | |
23 | produces 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 | |
36 | Set the variable $dont_use_nlink if you're using AFS, since AFS cheats. |
37 | |
38 | Here's another interesting wanted function. It will find all symlinks |
39 | that don't resolve: |
40 | |
41 | sub wanted { |
42 | -l && !-e && print "bogus link: $name\n"; |
43 | } |
44 | |