find(1) 맨 페이지 - 윈디하나의 솔라나라

개요

섹션
맨페이지이름
검색(S)

find(1)

Name
     find - find files

Synopsis
     /usr/bin/find [-H | -L] path... expression


     /usr/xpg4/bin/find [-H | -L] path... expression

Description
     The find utility recursively descends the directory  hierar-
     chy for each path seeking files that match a Boolean expres-
     sion written in the primaries specified below.


     find is able to  descend  to  arbitrary  depths  in  a  file
     hierarchy  and  does not fail due to path length limitations
     (unless a path operand specified by the application  exceeds
     PATH_MAX requirements).


     find detects infinite loops; that is, entering a  previously
     visited  directory  that  is  an  ancestor  of the last file
     encountered.

Options
     The following options are supported:

     -H
           Causes the file information and  file  type  evaluated
           for each symbolic link encountered on the command line
           to be those of the file referenced by  the  link,  and
           not  the  link itself. If the referenced file does not
           exist, the file information and type is for  the  link
           itself. File information for all symbolic links not on
           the command line is that of the link itself.


     -L
           Causes the file information and  file  type  evaluated
           for  each symbolic link to be those of the file refer-
           enced by the link, and not the link itself. See NOTES.



     Specifying more than one of the  mutually-exclusive  options
     -H and -L is not considered an error. The last option speci-
     fied determines the behavior of the utility.

Operands
     The following operands are supported:
     path
                   A pathname of a starting point in  the  direc-
                   tory hierarchy.


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

                   +n
                         more than n


                   n
                         exactly n


                   -n
                         less than n



  Expressions
     Valid expressions are:

     -acl
                       True if  the  file  have  additional  ACLs
                       defined.


     -amin n
                       File was last accessed n minutes ago.


     -atime n
                       True if the file was accessed n days  ago.
                       The  access time of directories in path is
                       changed by find itself.


     -cmin n
                       File's status was last changed  n  minutes
                       ago.


     -cpio device
                       Always true. Writes the  current  file  on
                       device in cpio format (5120-byte records).


     -ctime n
                       True if the file's status  was  changed  n
                       days ago.


     -depth
                       Always true. Causes descent of the  direc-
                       tory  hierarchy  to  be  done  so that all
                       entries in a directory are acted on before
                       the  directory  itself. This can be useful
                       when find is used with cpio(1) to transfer
                       files  that  are  contained in directories
                       without write permission.


     -exec command
                       True if the  executed  command  returns  a
                       zero value as exit status. The end of com-
                       mand must  be  punctuated  by  an  escaped
                       semicolon  (;).  A  command argument {} is
                       replaced by the current pathname.  If  the
                       last  argument  to  -exec  is  {}  and you
                       specify + rather than the  semicolon  (;),
                       the  command  is invoked fewer times, with
                       {} replaced by groups of pathnames. If any
                       invocation  of  the command returns a non-
                       zero value as exit status, find returns  a
                       non-zero exit status.


     -follow
                       Always true and always evaluated no matter
                       where   it   appears  in  expression.  The
                       behavior is unspecified if -follow is used
                       when  the  find  command  is  invoked with
                       either the -H or  the  -L  option.  Causes
                       symbolic  links  to be followed. When fol-
                       lowing symbolic links, find keeps track of
                       the  directories  visited  so  that it can
                       detect infinite loops. For example, such a
                       loop   would  occur  if  a  symbolic  link
                       pointed to an  ancestor.  This  expression
                       should  not  be  used with the find-type l
                       expression. See NOTES.


     -fstype type
                       True if the filesystem to which  the  file
                       belongs is of type type.


     -group gname
                       True if the  file  belongs  to  the  group
                       gname.  If  gname  is numeric and does not
                       appear in the  group(4)  database,  it  is
                       taken as a group ID.


     -iname pattern
                       Similar to -name, but  the  match  between
                       the  pattern  and  the  base  name  of the
                       current file  name  is  case  insensitive.
                       (See  EXAMPLES).  Unlike the -name option,
                       there is no special treatment  in  leading
                       period  and  wildcard file name generation
                       characters can match file  names beginning
                       with  a  .  for  both   /usr/bin/find  and
                       /usr/xpg4/bin/find.


     -inum n
                       True if the file has inode number n.


     -links n
                       True if the file has n links.


     -local
                       True if the file  system  type  is  not  a
                       remote  file system type as defined in the
                       /etc/dfs/fstypes file. nfs is used as  the
                       default  remote  filesystem  type  if  the
                       /etc/dfs/fstypes file is not present.  The
                       -local  option  descends  the hierarchy of
                       non-local directories. See EXAMPLES for an
                       example  of  how to search for local files
                       without descending.


     -ls
                       Always  true.  Prints   current   pathname
                       together  with  its associated statistics.
                       These include (respectively):

                           o    inode number

                           o    size in kilobytes (1024 bytes)

                           o    protection mode

                           o    number of hard links

                           o    user

                           o    group

                           o    size in bytes

                           o    modification time.
                       If the file is a special  file,  the  size
                       field instead contains the major and minor
                       device numbers.

                       If the file is a symbolic link, the  path-
                       name of the linked-to file is printed pre-
                       ceded by `->'. The format is identical  to
                       that of ls -gilds (see ls(1B)).

                       Formatting  is  done  internally,  without
                       executing the ls program.

     -mmin n
                       File's data was last  modified  n  minutes
                       ago.


     -mount
                       Always true. Restricts the search  to  the
                       file   system   containing  the  directory
                       specified. Does not list mount  points  to
                       other file systems.


     -mtime n
                       True if the file's  data  was  modified  n
                       days ago.


     -name pattern
                       True if pattern matches  the  basename  of
                       the  current  file name. Normal shell file
                       name generation characters (see sh(1)) can
                       be  used.  A  backslash  (\) is used as an
                       escape character within the  pattern.  The
                       pattern  should  be escaped or quoted when
                       find is invoked from the shell.

                       Unless the  character  `.'  is  explicitly
                       specified  in  the beginning of pattern, a
                       current file name beginning with `.'  does
                       not     match     pattern    when    using
                       /usr/bin/find. /usr/xpg4/bin/find does not
                       make  this distinction; wildcard file name
                       generation characters can match file names
                       beginning with `.'.


     -ncpio device
                       Always true. Writes the  current  file  on
                       device   in  cpio  -c  format  (5120  byte
                       records).


     -newer file
                       True if the current file has been modified
                       more recently than the argument file.


     -nogroup
                       True if the file belongs to a group not in
                       the group(4) database.


     -nouser
                       True if the file belongs to a user not  in
                       the passwd(4) database.


     -ok command
                       Like -exec, except that the generated com-
                       mand  line is printed with a question mark
                       first,  and  is  executed  only   if   the
                       response is affirmative.


     -perm [-]mode
                       The mode argument  is  used  to  represent
                       file  mode bits. It is identical in format
                       to    the    symbolic    mode     operand,
                       symbolic_mode_list, described in chmod(1),
                       and is interpreted as follows. To start, a
                       template  is  assumed  with  all file mode
                       bits cleared. An op symbol of:

                       +
                               Set the appropriate mode  bits  in
                               the template


                       -
                               Clear the appropriate bits


                       =
                               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, to avoid ambiguity with
                       the optional  leading  hyphen.  Since  the
                       initial mode is all bits off, there are no
                       symbolic modes that need to use -  as  the
                       first character.

                       If the  hyphen  is  omitted,  the  primary
                       evaluates as true when the file permission
                       bits  exactly  match  the  value  of   the
                       resulting template.

                       Otherwise,  if  mode  is  prefixed  by   a
                       hyphen,  the  primary evaluates as true if
                       at least all the  bits  in  the  resulting
                       template  are  set  in the file permission
                       bits.


     -perm [-]onum
                       True if the file permission flags  exactly
                       match   the   octal   number   onum   (see
                       chmod(1)). If onum is prefixed by a  minus
                       sign  (-),  only  the bits that are set in
                       onum are compared with the file permission
                       flags,  and  the expression evaluates true
                       if they match.

     -print
                       Always true. Causes the  current  pathname
                       to be printed.


     -print0
                       Always true. Causes the  current  pathname
                       to   be printed followed by a null charac-
                       ter, rather  than  the  NEWLINE  character
                       that -printuses.

                       This allows file names that  contain  NEW-
                       LINEs  or other types of white space to be
                       correctly  interpreted  by  programs  that
                       process  the  find  output.   This  option
                       corresponds to the -0 option of  cpio  and
                       xargs.


     -prune
                       Always yields true. Does not  examine  any
                       directories  or  files  in  the  directory
                       structure below the pattern just  matched.
                       (See  EXAMPLES).  If  -depth is specified,
                       -prune has no effect.


     -size n[c]
                       True if the file is  n  blocks  long  (512
                       bytes per block). If n is followed by a c,
                       the size is in bytes.


     -type c
                       True if the type of the file is c, where c
                       is  b,  c,  d,  D, f, l, p, or s for block
                       special  file,  character  special   file,
                       directory,   door,  plain  file,  symbolic
                       link,  fifo  (named  pipe),   or   socket,
                       respectively.


     -user uname
                       True if  the  file  belongs  to  the  user
                       uname.  If  uname  is numeric and does not
                       appear as a login name  in  the  passwd(4)
                       database, it is taken as a user ID.


     -xdev
                       Same as the -mount primary.


     -xattr
                       True if the file has extended attributes.


  Complex Expressions
     The primaries can be combined using the following  operators
     (in order of decreasing precedence):
     1)(expression)
         True   if   the   parenthesized   expression   is   true
         (parentheses  are  special  to  the  shell  and  must be
         escaped).


     2)!expression
         The negation of a primary (! is the unary not operator).


     3) expression[-a] expression
         Concatenation of primaries (the and operation is implied
         by the juxtaposition of two primaries).


     4) expression-oexpression
         Alternation of primaries (-o is the or operator).



     When you use find in conjunction with cpio, if you  use  the
     -L option with cpio, you must use the -L option or the -fol-
     low primitive  with  find  and  vice  versa.  Otherwise  the
     results are unspecified.


     If no expression is present, -print is used as  the  expres-
     sion.  Otherwise,  if the specified expression does not con-
     tain any of the primaries -exec, -ok, -ls,  or  -print,  the
     specified expression is effectively replaced by:


     (specified) -print


     The -user, -group, and -newer primaries each evaluate  their
     respective arguments only once. Invocation of command speci-
     fied by -exec or -ok does not affect subsequent primaries on
     the same file.

Usage
     See largefile(5) for the description of the behavior of find
     when  encountering  files  greater  than or equal to 2 Gbyte
     (2^31 bytes).

Examples
     Example 1 Writing Out the Hierarchy Directory

     The following commands are equivalent:


       example% find .
       example% find . -print




     They both write out the entire directory hierarchy from  the
     current directory.


     Example 2 Removing Files


     The following comand removes all files in your  home  direc-
     tory  named  a.out  or *.o that have not been accessed for a
     week:


       example% find $HOME \( -name a.out -o -name `*.o' \) \
              -atime +7 -exec rm {} \;



     Example 3 Printing All File Names But Skipping  SCCS  Direc-
     tories


     The following command recursively print all  file  names  in
     the  current  directory  and below, but skipping SCCS direc-
     tories:


       example% find . -name SCCS -prune -o -print



     Example 4 Printing all file names  and  the  SCCS  directory
     name


     Recursively print all file names in  the  current  directory
     and  below,  skipping  the contents of SCCS directories, but
     printing out the SCCS directory name:


       example% find . -print -name SCCS -prune

     Example 5 Testing for the Newer File


     The following command is basically  equivalent  to  the  -nt
     extension to test(1):


       example$ if [ -n "$(find
       file1 -prune -newer file2)" ]; then

       printf %s\\n "file1 is newer than file2"



     Example 6 Selecting a File Using 24-hour Mode


     The descriptions of -atime, -ctime, and -mtime use the  ter-
     minology n ``24-hour periods''. For example, a file accessed
     at 23:59 is selected by:


       example% find . -atime -1 -print




     at 00:01 the next day (less than 24 hours  later,  not  more
     than one day ago). The midnight boundary between days has no
     effect on the 24-hour calculation.


     Example 7 Printing Files Matching a User's Permission Mode


     The following command recursively print all file names whose
     permission  mode  exactly  matches  read, write, and execute
     access for user, and read and execute access for  group  and
     other:


       example% find . -perm u=rwx,g=rx,o=rx




     The above could alternatively be specified as follows:


       example% find . -perm a=rwx,g-w,o-w

     Example 8 Printing Files with Write Access for other


     The following command recursively print all file names whose
     permission includes, but is not limited to, write access for
     other:


       example% find . -perm -o+w



     Example 9 Printing Local Files without Descending  Non-local
     Directories

       example% find . ! -local -prune -o -print



     Example 10 Printing the Files in the Name  Space  Possessing
     Extended Attributes

       example% find . -xattr



     Example 11 Printing all PDF Filenames Regardless of Case


     The following example finds all file names with an extension
     of .pdf, .PDF, .Pdf, and so forth.


       example% find . -iname `*.pdf'

Environment Variables
     See environ(5) for descriptions of the following environment
     variables  that  affect the execution of find: LANG, LC_ALL,
     LC_COLLATE, LC_CTYPE, LC_MESSAGES, and NLSPATH.

     PATH
             Determine the location of the utility_name  for  the
             -exec and -ok primaries.



     Affirmative responses are processed using the extended regu-
     lar  expression  defined  for  the  yesexpr  keyword  in the
     LC_MESSAGES category of the user's locale. The locale speci-
     fied  in  the  LC_COLLATE  category  defines the behavior of
     ranges, equivalence classes, and  multi-character  collating
     elements  used  in  the  expression defined for yesexpr. The
     locale specified  in  LC_CTYPE  determines  the  locale  for
     interpretation  of sequences of bytes of text data a charac-
     ters, the behavior of character classes used in the  expres-
     sion defined for the yesexpr. See locale(5).

Exit Status
     The following exit values are returned:

     0
           All path operands were traversed successfully.


     >0
           An error occurred.

Files
     /etc/passwd
                         Password file


     /etc/group
                         Group file


     /etc/dfs/fstypes
                         File  that  registers  distributed  file
                         system packages

Attributes
     See attributes(5) for descriptions of the  following  attri-
     butes:



     tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i)  ATTRI-
     BUTE  TYPEATTRIBUTE  VALUE  _  Availabilitysystem/core-os  _
     CSIEnabled  _  Interface  StabilityCommitted  _  StandardSee
     standards(5).

See Also
     chmod(1), cpio(1), sh(1), test(1), ls(1B), acl(2),  stat(2),
     umask(2),  group(4),  passwd(4),  attributes(5), environ(5),
     fsattr(5), largefile(5), locale(5), standards(5)

Warnings
     The following options are obsolete and will not be supported
     in future releases:

     -cpio device
                      Always true. Writes  the  current  file  on
                      device in cpio format (5120-byte records).

     -ncpio device
                      Always true. Writes  the  current  file  on
                      device   in   cpio   -c  format  (5120-byte
                      records).

Notes
     When using find to determine files modified within  a  range
     of time, use the -mtime argument before the -print argument.
     Otherwise, find gives all files.


     Some files that might be under the Solaris root file  system
     are  actually mount points for virtual file systems, such as
     mntfs or namefs. When comparing against a ufs  file  system,
     such  files are not selected if -mount or -xdev is specified
     in the find expression.


     Using the -L or -follow option is not recommended when  des-
     cending a file-system hierarchy that is under the control of
     other users. In particular, when using -exec, symbolic links
     can  lead  the find command out of the hierarchy in which it
     started. Using -type is not sufficient to restrict the  type
     of  files on which the -exec command operates, because there
     is an inherent race condition between  the  type-check  per-
     formed by the find command and the time the executed command
     operates on the file argument.
맨 페이지 내용의 저작권은 맨 페이지 작성자에게 있습니다.
RSS ATOM XHTML 5 CSS3