Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   find.1p    ( 1 )

найти файлы (find files)

Операнды (Operands)

The following operands shall be supported:

The first operand and subsequent operands up to but not including the first operand that starts with a '-', or is a '!' or a '(', shall be interpreted as path operands. If the first operand starts with a '-', or is a '!' or a '(', the behavior is unspecified. Each path operand is a pathname of a starting point in the file hierarchy.

The first operand that starts with a '-', or is a '!' or a '(', and all subsequent arguments shall be interpreted as an expression made up of the following primaries and operators. In the descriptions, wherever n is used as a primary argument, it shall be interpreted as a decimal integer optionally preceded by a <plus-sign> ('+') or <hyphen-minus> ('-'), as follows:

+n More than n.

n Exactly n.

-n Less than n.

The following primaries shall be supported:

-name pattern The primary shall evaluate as true if the basename of the current pathname matches pattern using the pattern matching notation described in Section 2.13, Pattern Matching Notation. The additional rules in Section 2.13.3, Patterns Used for Filename Expansion do not apply as this is a matching operation, not an expansion.

-path pattern The primary shall evaluate as true if the current pathname matches pattern using the pattern matching notation described in Section 2.13, Pattern Matching Notation. The additional rules in Section 2.13.3, Patterns Used for Filename Expansion do not apply as this is a matching operation, not an expansion.

-nouser The primary shall evaluate as true if the file belongs to a user ID for which the getpwuid() function defined in the System Interfaces volume of POSIX.1‐2017 (or equivalent) returns NULL.

-nogroup The primary shall evaluate as true if the file belongs to a group ID for which the getgrgid() function defined in the System Interfaces volume of POSIX.1‐2017 (or equivalent) returns NULL.

-xdev The primary shall always evaluate as true; it shall cause find not to continue descending past directories that have a different device ID (st_dev, see the stat() function defined in the System Interfaces volume of POSIX.1‐2017). If any -xdev primary is specified, it shall apply to the entire expression even if the -xdev primary would not normally be evaluated.

-prune The primary shall always evaluate as true; it shall cause find not to descend the current pathname if it is a directory. If the -depth primary is specified, the -prune primary shall have no effect.

-perm [-]mode The mode argument is used to represent file mode bits. It shall be identical in format to the symbolic_mode operand described in chmod, and shall be interpreted as follows. To start, a template shall be assumed with all file mode bits cleared. An op symbol of '+' shall set the appropriate mode bits in the template; '-' shall clear the appropriate bits; '=' shall set the appropriate mode bits, without regard to the contents of the file mode creation mask of the process. The op symbol of '-' cannot be the first character of mode; this avoids ambiguity with the optional leading <hyphen-minus>. Since the initial mode is all bits off, there are not any symbolic modes that need to use '-' as the first character.

If the <hyphen-minus> is omitted, the primary shall evaluate as true when the file permission bits exactly match the value of the resulting template.

Otherwise, if mode is prefixed by a <hyphen-minus>, the primary shall evaluate as true if at least all the bits in the resulting template are set in the file permission bits.

-perm [-]onum If the <hyphen-minus> is omitted, the primary shall evaluate as true when the file mode bits exactly match the value of the octal number onum (see the description of the octal mode in chmod). Otherwise, if onum is prefixed by a <hyphen-minus>, the primary shall evaluate as true if at least all of the bits specified in onum are set. In both cases, the behavior is unspecified when onum exceeds 07777.

-type c The primary shall evaluate as true if the type of the file is c, where c is 'b', 'c', 'd', 'l', 'p', 'f', or 's' for block special file, character special file, directory, symbolic link, FIFO, regular file, or socket, respectively.

-links n The primary shall evaluate as true if the file has n links.

-user uname The primary shall evaluate as true if the file belongs to the user uname. If uname is a decimal integer and the getpwnam() (or equivalent) function does not return a valid user name, uname shall be interpreted as a user ID.

-group gname The primary shall evaluate as true if the file belongs to the group gname. If gname is a decimal integer and the getgrnam() (or equivalent) function does not return a valid group name, gname shall be interpreted as a group ID.

-size n[c] The primary shall evaluate as true if the file size in bytes, divided by 512 and rounded up to the next integer, is n. If n is followed by the character 'c', the size shall be in bytes.

-atime n The primary shall evaluate as true if the file access time subtracted from the initialization time, divided by 86400 (with any remainder discarded), is n.

-ctime n The primary shall evaluate as true if the time of last change of file status information subtracted from the initialization time, divided by 86400 (with any remainder discarded), is n.

-mtime n The primary shall evaluate as true if the file modification time subtracted from the initialization time, divided by 86400 (with any remainder discarded), is n.

-exec utility_name [argument ...] ;

-exec utility_name [argument ...] {} + The end of the primary expression shall be punctuated by a <semicolon> or by a <plus-sign>. Only a <plus- sign> that immediately follows an argument containing only the two characters "{}" shall punctuate the end of the primary expression. Other uses of the <plus-sign> shall not be treated as special.

If the primary expression is punctuated by a <semicolon>, the utility utility_name shall be invoked once for each pathname and the primary shall evaluate as true if the utility returns a zero value as exit status. A utility_name or argument containing only the two characters "{}" shall be replaced by the current pathname. If a utility_name or argument string contains the two characters "{}", but not just the two characters "{}", it is implementation-defined whether find replaces those two characters or uses the string without change.

If the primary expression is punctuated by a <plus- sign>, the primary shall always evaluate as true, and the pathnames for which the primary is evaluated shall be aggregated into sets. The utility utility_name shall be invoked once for each set of aggregated pathnames. Each invocation shall begin after the last pathname in the set is aggregated, and shall be completed before the find utility exits and before the first pathname in the next set (if any) is aggregated for this primary, but it is otherwise unspecified whether the invocation occurs before, during, or after the evaluations of other primaries. If any invocation returns a non-zero value as exit status, the find utility shall return a non-zero exit status. An argument containing only the two characters "{}" shall be replaced by the set of aggregated pathnames, with each pathname passed as a separate argument to the invoked utility in the same order that it was aggregated. The size of any set of two or more pathnames shall be limited such that execution of the utility does not cause the system's {ARG_MAX} limit to be exceeded. If more than one argument containing the two characters "{}" is present, the behavior is unspecified.

The current directory for the invocation of utility_name shall be the same as the current directory when the find utility was started. If the utility_name names any of the special built-in utilities (see Section 2.14, Special Built-In Utilities), the results are undefined.

-ok utility_name [argument ...] ; The -ok primary shall be equivalent to -exec, except that the use of a <plus-sign> to punctuate the end of the primary expression need not be supported, and find shall request affirmation of the invocation of utility_name using the current file as an argument by writing to standard error as described in the STDERR section. If the response on standard input is affirmative, the utility shall be invoked. Otherwise, the command shall not be invoked and the value of the -ok operand shall be false.

-print The primary shall always evaluate as true; it shall cause the current pathname to be written to standard output.

-newer file The primary shall evaluate as true if the modification time of the current file is more recent than the modification time of the file named by the pathname file.

-depth The primary shall always evaluate as true; it shall cause descent of the directory hierarchy to be done so that all entries in a directory are acted on before the directory itself. If a -depth primary is not specified, all entries in a directory shall be acted on after the directory itself. If any -depth primary is specified, it shall apply to the entire expression even if the -depth primary would not normally be evaluated.

The primaries can be combined using the following operators (in order of decreasing precedence):

( expression ) True if expression is true.

! expression Negation of a primary; the unary NOT operator.

expression [-a] expression Conjunction of primaries; the AND operator is implied by the juxtaposition of two primaries or made explicit by the optional -a operator. The second expression shall not be evaluated if the first expression is false.

expression -o expression Alternation of primaries; the OR operator. The second expression shall not be evaluated if the first expression is true.

If no expression is present, -print shall be used as the expression. Otherwise, if the given expression does not contain any of the primaries -exec, -ok, or -print, the given expression shall be effectively replaced by:

( given_expression ) -print

The -user, -group, and -newer primaries each shall evaluate their respective arguments only once.

When the file type evaluated for the current file is a symbolic link, the results of evaluating the -perm primary are implementation-defined.