поиск файлов в иерархии каталогов (search for files in a directory hierarchy)
Стандарты (Conforming to)
For closest compliance to the POSIX standard, you should set the
POSIXLY_CORRECT
environment variable. The following options are
specified in the POSIX standard (IEEE Std 1003.1-2008, 2016
Edition):
-H
This option is supported.
-L
This option is supported.
-name
This option is supported, but POSIX conformance depends on
the POSIX conformance of the system's fnmatch(3) library
function. As of findutils-4.2.2, shell metacharacters
(`*', `?' or `[]' for example) match a leading `.',
because IEEE PASC interpretation 126 requires this. This
is a change from previous versions of findutils.
-type
Supported. POSIX specifies `b', `c', `d', `l', `p', `f'
and `s'. GNU find also supports `D', representing a Door,
where the OS provides these. Furthermore, GNU find allows
multiple types to be specified at once in a comma-
separated list.
-ok
Supported. Interpretation of the response is according to
the `yes' and `no' patterns selected by setting the
LC_MESSAGES
environment variable. When the
POSIXLY_CORRECT
environment variable is set, these
patterns are taken system's definition of a positive (yes)
or negative (no) response. See the system's documentation
for nl_langinfo(3), in particular YESEXPR and NOEXPR.
When POSIXLY_CORRECT
is not set, the patterns are instead
taken from find
's own message catalogue.
-newer
Supported. If the file specified is a symbolic link, it
is always dereferenced. This is a change from previous
behaviour, which used to take the relevant time from the
symbolic link; see the HISTORY section below.
-perm
Supported. If the POSIXLY_CORRECT
environment variable is
not set, some mode arguments (for example +a+x) which are
not valid in POSIX are supported for backward-
compatibility.
Other primaries
The primaries -atime
, -ctime
, -depth
, -exec
, -group
,
-links
, -mtime
, -nogroup
, -nouser
, -ok
, -path
, -print
,
-prune
, -size
, -user
and -xdev
are all supported.
The POSIX standard specifies parentheses `(', `)', negation `!'
and the logical AND/OR operators -a
and -o
.
All other options, predicates, expressions and so forth are
extensions beyond the POSIX standard. Many of these extensions
are not unique to GNU find, however.
The POSIX standard requires that find
detects loops:
The find
utility shall detect infinite loops; that is,
entering a previously visited directory that is an
ancestor of the last file encountered. When it detects an
infinite loop, find shall write a diagnostic message to
standard error and shall either recover its position in
the hierarchy or terminate.
GNU find
complies with these requirements. The link count of
directories which contain entries which are hard links to an
ancestor will often be lower than they otherwise should be. This
can mean that GNU find will sometimes optimise away the visiting
of a subdirectory which is actually a link to an ancestor. Since
find
does not actually enter such a subdirectory, it is allowed
to avoid emitting a diagnostic message. Although this behaviour
may be somewhat confusing, it is unlikely that anybody actually
depends on this behaviour. If the leaf optimisation has been
turned off with -noleaf
, the directory entry will always be
examined and the diagnostic message will be issued where it is
appropriate. Symbolic links cannot be used to create filesystem
cycles as such, but if the -L
option or the -follow
option is in
use, a diagnostic message is issued when find
encounters a loop
of symbolic links. As with loops containing hard links, the leaf
optimisation will often mean that find
knows that it doesn't need
to call stat() or chdir() on the symbolic link, so this
diagnostic is frequently not necessary.
The -d
option is supported for compatibility with various BSD
systems, but you should use the POSIX-compliant option -depth
instead.
The POSIXLY_CORRECT
environment variable does not affect the
behaviour of the -regex
or -iregex
tests because those tests
aren't specified in the POSIX standard.