Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / man / man3 / File::Find.3
.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "File::Find 3"
.TH File::Find 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
.SH "NAME"
File::Find \- Traverse a directory tree.
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 3
\& use File::Find;
\& find(\e&wanted, @directories_to_search);
\& sub wanted { ... }
.Ve
.PP
.Vb 3
\& use File::Find;
\& finddepth(\e&wanted, @directories_to_search);
\& sub wanted { ... }
.Ve
.PP
.Vb 2
\& use File::Find;
\& find({ wanted => \e&process, follow => 1 }, '.');
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
These are functions for searching through directory trees doing work
on each file found similar to the Unix \fIfind\fR command. File::Find
exports two functions, \f(CW\*(C`find\*(C'\fR and \f(CW\*(C`finddepth\*(C'\fR. They work similarly
but have subtle differences.
.IP "\fBfind\fR" 4
.IX Item "find"
.Vb 2
\& find(\e&wanted, @directories);
\& find(\e%options, @directories);
.Ve
.Sp
\&\f(CW\*(C`find()\*(C'\fR does a depth-first search over the given \f(CW@directories\fR in
the order they are given. For each file or directory found, it calls
the \f(CW&wanted\fR subroutine. (See below for details on how to use the
\&\f(CW&wanted\fR function). Additionally, for each directory found, it will
\&\f(CW\*(C`chdir()\*(C'\fR into that directory and continue the search, invoking the
\&\f(CW&wanted\fR function on each file or subdirectory in the directory.
.IP "\fBfinddepth\fR" 4
.IX Item "finddepth"
.Vb 2
\& finddepth(\e&wanted, @directories);
\& finddepth(\e%options, @directories);
.Ve
.Sp
\&\f(CW\*(C`finddepth()\*(C'\fR works just like \f(CW\*(C`find()\*(C'\fR except that is invokes the
\&\f(CW&wanted\fR function for a directory \fIafter\fR invoking it for the
directory's contents. It does a postorder traversal instead of a
preorder traversal, working from the bottom of the directory tree up
where \f(CW\*(C`find()\*(C'\fR works from the top of the tree down.
.Sh "%options"
.IX Subsection "%options"
The first argument to \f(CW\*(C`find()\*(C'\fR is either a code reference to your
\&\f(CW&wanted\fR function, or a hash reference describing the operations
to be performed for each file. The
code reference is described in \*(L"The wanted function\*(R" below.
.PP
Here are the possible keys for the hash:
.ie n .IP """wanted""" 3
.el .IP "\f(CWwanted\fR" 3
.IX Item "wanted"
The value should be a code reference. This code reference is
described in \*(L"The wanted function\*(R" below.
.ie n .IP """bydepth""" 3
.el .IP "\f(CWbydepth\fR" 3
.IX Item "bydepth"
Reports the name of a directory only \s-1AFTER\s0 all its entries
have been reported. Entry point \f(CW\*(C`finddepth()\*(C'\fR is a shortcut for
specifying \f(CW\*(C`<{ bydepth =\*(C'\fR 1 }>> in the first argument of \f(CW\*(C`find()\*(C'\fR.
.ie n .IP """preprocess""" 3
.el .IP "\f(CWpreprocess\fR" 3
.IX Item "preprocess"
The value should be a code reference. This code reference is used to
preprocess the current directory. The name of the currently processed
directory is in \f(CW$File::Find::dir\fR. Your preprocessing function is
called after \f(CW\*(C`readdir()\*(C'\fR, but before the loop that calls the \f(CW\*(C`wanted()\*(C'\fR
function. It is called with a list of strings (actually file/directory
names) and is expected to return a list of strings. The code can be
used to sort the file/directory names alphabetically, numerically,
or to filter out directory entries based on their name alone. When
\&\fIfollow\fR or \fIfollow_fast\fR are in effect, \f(CW\*(C`preprocess\*(C'\fR is a no\-op.
.ie n .IP """postprocess""" 3
.el .IP "\f(CWpostprocess\fR" 3
.IX Item "postprocess"
The value should be a code reference. It is invoked just before leaving
the currently processed directory. It is called in void context with no
arguments. The name of the current directory is in \f(CW$File::Find::dir\fR. This
hook is handy for summarizing a directory, such as calculating its disk
usage. When \fIfollow\fR or \fIfollow_fast\fR are in effect, \f(CW\*(C`postprocess\*(C'\fR is a
no\-op.
.ie n .IP """follow""" 3
.el .IP "\f(CWfollow\fR" 3
.IX Item "follow"
Causes symbolic links to be followed. Since directory trees with symbolic
links (followed) may contain files more than once and may even have
cycles, a hash has to be built up with an entry for each file.
This might be expensive both in space and time for a large
directory tree. See \fIfollow_fast\fR and \fIfollow_skip\fR below.
If either \fIfollow\fR or \fIfollow_fast\fR is in effect:
.RS 3
.IP "*" 6
It is guaranteed that an \fIlstat\fR has been called before the user's
\&\f(CW\*(C`wanted()\*(C'\fR function is called. This enables fast file checks involving _.
Note that this guarantee no longer holds if \fIfollow\fR or \fIfollow_fast\fR
are not set.
.IP "*" 6
There is a variable \f(CW$File::Find::fullname\fR which holds the absolute
pathname of the file with all symbolic links resolved. If the link is
a dangling symbolic link, then fullname will be set to \f(CW\*(C`undef\*(C'\fR.
.RE
.RS 3
.Sp
This is a no-op on Win32.
.RE
.ie n .IP """follow_fast""" 3
.el .IP "\f(CWfollow_fast\fR" 3
.IX Item "follow_fast"
This is similar to \fIfollow\fR except that it may report some files more
than once. It does detect cycles, however. Since only symbolic links
have to be hashed, this is much cheaper both in space and time. If
processing a file more than once (by the user's \f(CW\*(C`wanted()\*(C'\fR function)
is worse than just taking time, the option \fIfollow\fR should be used.
.Sp
This is also a no-op on Win32.
.ie n .IP """follow_skip""" 3
.el .IP "\f(CWfollow_skip\fR" 3
.IX Item "follow_skip"
\&\f(CW\*(C`follow_skip==1\*(C'\fR, which is the default, causes all files which are
neither directories nor symbolic links to be ignored if they are about
to be processed a second time. If a directory or a symbolic link
are about to be processed a second time, File::Find dies.
.Sp
\&\f(CW\*(C`follow_skip==0\*(C'\fR causes File::Find to die if any file is about to be
processed a second time.
.Sp
\&\f(CW\*(C`follow_skip==2\*(C'\fR causes File::Find to ignore any duplicate files and
directories but to proceed normally otherwise.
.ie n .IP """dangling_symlinks""" 3
.el .IP "\f(CWdangling_symlinks\fR" 3
.IX Item "dangling_symlinks"
If true and a code reference, will be called with the symbolic link
name and the directory it lives in as arguments. Otherwise, if true
and warnings are on, warning \*(L"symbolic_link_name is a dangling
symbolic link\en\*(R" will be issued. If false, the dangling symbolic link
will be silently ignored.
.ie n .IP """no_chdir""" 3
.el .IP "\f(CWno_chdir\fR" 3
.IX Item "no_chdir"
Does not \f(CW\*(C`chdir()\*(C'\fR to each directory as it recurses. The \f(CW\*(C`wanted()\*(C'\fR
function will need to be aware of this, of course. In this case,
\&\f(CW$_\fR will be the same as \f(CW$File::Find::name\fR.
.ie n .IP """untaint""" 3
.el .IP "\f(CWuntaint\fR" 3
.IX Item "untaint"
If find is used in taint-mode (\-T command line switch or if \s-1EUID\s0 != \s-1UID\s0
or if \s-1EGID\s0 != \s-1GID\s0) then internally directory names have to be untainted
before they can be chdir'ed to. Therefore they are checked against a regular
expression \fIuntaint_pattern\fR. Note that all names passed to the user's
\&\fI\fIwanted()\fI\fR function are still tainted. If this option is used while
not in taint\-mode, \f(CW\*(C`untaint\*(C'\fR is a no\-op.
.ie n .IP """untaint_pattern""" 3
.el .IP "\f(CWuntaint_pattern\fR" 3
.IX Item "untaint_pattern"
See above. This should be set using the \f(CW\*(C`qr\*(C'\fR quoting operator.
The default is set to \f(CW\*(C`qr|^([\-+@\ew./]+)$|\*(C'\fR.
Note that the parentheses are vital.
.ie n .IP """untaint_skip""" 3
.el .IP "\f(CWuntaint_skip\fR" 3
.IX Item "untaint_skip"
If set, a directory which fails the \fIuntaint_pattern\fR is skipped,
including all its sub\-directories. The default is to 'die' in such a case.
.Sh "The wanted function"
.IX Subsection "The wanted function"
The \f(CW\*(C`wanted()\*(C'\fR function does whatever verifications you want on
each file and directory. Note that despite its name, the \f(CW\*(C`wanted()\*(C'\fR
function is a generic callback function, and does \fBnot\fR tell
File::Find if a file is \*(L"wanted\*(R" or not. In fact, its return value
is ignored.
.PP
The wanted function takes no arguments but rather does its work
through a collection of variables.
.ie n .IP "$File::Find::dir is the current directory name," 4
.el .IP "\f(CW$File::Find::dir\fR is the current directory name," 4
.IX Item "$File::Find::dir is the current directory name,"
.PD 0
.ie n .IP "$_ is the current filename within that directory" 4
.el .IP "\f(CW$_\fR is the current filename within that directory" 4
.IX Item "$_ is the current filename within that directory"
.ie n .IP "$File::Find::name is the complete pathname to the file." 4
.el .IP "\f(CW$File::Find::name\fR is the complete pathname to the file." 4
.IX Item "$File::Find::name is the complete pathname to the file."
.PD
.PP
Don't modify these variables.
.PP
For example, when examining the file \fI/some/path/foo.ext\fR you will have:
.PP
.Vb 3
\& $File::Find::dir = /some/path/
\& $_ = foo.ext
\& $File::Find::name = /some/path/foo.ext
.Ve
.PP
You are \fIchdir()\fR'd to \f(CW$File::Find::dir\fR when the function is called,
unless \f(CW\*(C`no_chdir\*(C'\fR was specified. Note that when changing to
directories is in effect the root directory (\fI/\fR) is a somewhat
special case inasmuch as the concatenation of \f(CW$File::Find::dir\fR,
\&\f(CW'/'\fR and \f(CW$_\fR is not literally equal to \f(CW$File::Find::name\fR. The
table below summarizes all variants:
.PP
.Vb 4
\& $File::Find::name $File::Find::dir $_
\& default / / .
\& no_chdir=>0 /etc / etc
\& /etc/x /etc x
.Ve
.PP
.Vb 3
\& no_chdir=>1 / / /
\& /etc / /etc
\& /etc/x /etc /etc/x
.Ve
.PP
When <follow> or <follow_fast> are in effect, there is
also a \f(CW$File::Find::fullname\fR. The function may set
\&\f(CW$File::Find::prune\fR to prune the tree unless \f(CW\*(C`bydepth\*(C'\fR was
specified. Unless \f(CW\*(C`follow\*(C'\fR or \f(CW\*(C`follow_fast\*(C'\fR is specified, for
compatibility reasons (find.pl, find2perl) there are in addition the
following globals available: \f(CW$File::Find::topdir\fR,
\&\f(CW$File::Find::topdev\fR, \f(CW$File::Find::topino\fR,
\&\f(CW$File::Find::topmode\fR and \f(CW$File::Find::topnlink\fR.
.PP
This library is useful for the \f(CW\*(C`find2perl\*(C'\fR tool, which when fed,
.PP
.Vb 2
\& find2perl / -name .nfs\e* -mtime +7 \e
\& -exec rm -f {} \e; -o -fstype nfs -prune
.Ve
.PP
produces something like:
.PP
.Vb 10
\& sub wanted {
\& /^\e.nfs.*\ez/s &&
\& (($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_)) &&
\& int(-M _) > 7 &&
\& unlink($_)
\& ||
\& ($nlink || (($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_))) &&
\& $dev < 0 &&
\& ($File::Find::prune = 1);
\& }
.Ve
.PP
Notice the \f(CW\*(C`_\*(C'\fR in the above \f(CW\*(C`int(\-M _)\*(C'\fR: the \f(CW\*(C`_\*(C'\fR is a magical
filehandle that caches the information from the preceding
\&\f(CW\*(C`stat()\*(C'\fR, \f(CW\*(C`lstat()\*(C'\fR, or filetest.
.PP
Here's another interesting wanted function. It will find all symbolic
links that don't resolve:
.PP
.Vb 3
\& sub wanted {
\& -l && !-e && print "bogus link: $File::Find::name\en";
\& }
.Ve
.PP
See also the script \f(CW\*(C`pfind\*(C'\fR on \s-1CPAN\s0 for a nice application of this
module.
.SH "WARNINGS"
.IX Header "WARNINGS"
If you run your program with the \f(CW\*(C`\-w\*(C'\fR switch, or if you use the
\&\f(CW\*(C`warnings\*(C'\fR pragma, File::Find will report warnings for several weird
situations. You can disable these warnings by putting the statement
.PP
.Vb 1
\& no warnings 'File::Find';
.Ve
.PP
in the appropriate scope. See perllexwarn for more info about lexical
warnings.
.SH "CAVEAT"
.IX Header "CAVEAT"
.IP "$dont_use_nlink" 2
.IX Item "$dont_use_nlink"
You can set the variable \f(CW$File::Find::dont_use_nlink\fR to 1, if you want to
force File::Find to always stat directories. This was used for file systems
that do not have an \f(CW\*(C`nlink\*(C'\fR count matching the number of sub\-directories.
Examples are \s-1ISO\-9660\s0 (\s-1CD\-ROM\s0), \s-1AFS\s0, \s-1HPFS\s0 (\s-1OS/2\s0 file system), \s-1FAT\s0 (\s-1DOS\s0 file
system) and a couple of others.
.Sp
You shouldn't need to set this variable, since File::Find should now detect
such file systems on-the-fly and switch itself to using stat. This works even
for parts of your file system, like a mounted \s-1CD\-ROM\s0.
.Sp
If you do set \f(CW$File::Find::dont_use_nlink\fR to 1, you will notice slow\-downs.
.IP "symlinks" 2
.IX Item "symlinks"
Be aware that the option to follow symbolic links can be dangerous.
Depending on the structure of the directory tree (including symbolic
links to directories) you might traverse a given (physical) directory
more than once (only if \f(CW\*(C`follow_fast\*(C'\fR is in effect).
Furthermore, deleting or changing files in a symbolically linked directory
might cause very unpleasant surprises, since you delete or change files
in an unknown directory.
.SH "NOTES"
.IX Header "NOTES"
.IP "\(bu" 4
Mac \s-1OS\s0 (Classic) users should note a few differences:
.RS 4
.IP "\(bu" 4
The path separator is ':', not '/', and the current directory is denoted
as ':', not '.'. You should be careful about specifying relative pathnames.
While a full path always begins with a volume name, a relative pathname
should always begin with a ':'. If specifying a volume name only, a
trailing ':' is required.
.IP "\(bu" 4
\&\f(CW$File::Find::dir\fR is guaranteed to end with a ':'. If \f(CW$_\fR
contains the name of a directory, that name may or may not end with a
\&':'. Likewise, \f(CW$File::Find::name\fR, which contains the complete
pathname to that directory, and \f(CW$File::Find::fullname\fR, which holds
the absolute pathname of that directory with all symbolic links resolved,
may or may not end with a ':'.
.IP "\(bu" 4
The default \f(CW\*(C`untaint_pattern\*(C'\fR (see above) on Mac \s-1OS\s0 is set to
\&\f(CW\*(C`qr|^(.+)$|\*(C'\fR. Note that the parentheses are vital.
.IP "\(bu" 4
The invisible system file \*(L"Icon\e015\*(R" is ignored. While this file may
appear in every directory, there are some more invisible system files
on every volume, which are all located at the volume root level (i.e.
\&\*(L"MacintoshHD:\*(R"). These system files are \fBnot\fR excluded automatically.
Your filter may use the following code to recognize invisible files or
directories (requires Mac::Files):
.Sp
.Vb 1
\& use Mac::Files;
.Ve
.Sp
.Vb 2
\& # invisible() -- returns 1 if file/directory is invisible,
\& # 0 if it's visible or undef if an error occurred
.Ve
.Sp
.Vb 4
\& sub invisible($) {
\& my $file = shift;
\& my ($fileCat, $fileInfo);
\& my $invisible_flag = 1 << 14;
.Ve
.Sp
.Vb 7
\& if ( $fileCat = FSpGetCatInfo($file) ) {
\& if ($fileInfo = $fileCat->ioFlFndrInfo() ) {
\& return (($fileInfo->fdFlags & $invisible_flag) && 1);
\& }
\& }
\& return undef;
\& }
.Ve
.Sp
Generally, invisible files are system files, unless an odd application
decides to use invisible files for its own purposes. To distinguish
such files from system files, you have to look at the \fBtype\fR and \fBcreator\fR
file attributes. The MacPerl built-in functions \f(CW\*(C`GetFileInfo(FILE)\*(C'\fR and
\&\f(CW\*(C`SetFileInfo(CREATOR, TYPE, FILES)\*(C'\fR offer access to these attributes
(see MacPerl.pm for details).
.Sp
Files that appear on the desktop actually reside in an (hidden) directory
named \*(L"Desktop Folder\*(R" on the particular disk volume. Note that, although
all desktop files appear to be on the same \*(L"virtual\*(R" desktop, each disk
volume actually maintains its own \*(L"Desktop Folder\*(R" directory.
.RE
.RS 4
.RE
.SH "BUGS AND CAVEATS"
.IX Header "BUGS AND CAVEATS"
Despite the name of the \f(CW\*(C`finddepth()\*(C'\fR function, both \f(CW\*(C`find()\*(C'\fR and
\&\f(CW\*(C`finddepth()\*(C'\fR perform a depth-first search of the directory
hierarchy.
.SH "HISTORY"
.IX Header "HISTORY"
File::Find used to produce incorrect results if called recursively.
During the development of perl 5.8 this bug was fixed.
The first fixed version of File::Find was 1.01.