


find(1)                   User Commands                   find(1)



NAME
     find - find files

SYNOPSIS
     find _p_a_t_h..._e_x_p_r_e_s_s_i_o_n

AVAILABILITY
     SUNWcsu

DESCRIPTION
     The find command recursively descends the directory  hierar-
     chy for each _p_a_t_h seeking files that match a Boolean _e_x_p_r_e_s_-
     _s_i_o_n written in the primaries given below.

     find will be able to descend to arbitrary depths in  a  file
     hierarchy  and  will not fail due to path length limitations
     (unless a _p_a_t_h operand specified by the application  exceeds
     PATH_MAX requirements).

OPERANDS
     The following operands are supported:

     _p_a_t_h           a path name of a starting point in the direc-
                    tory hierarchy.

     The first argument that starts with a -, or is a ! or  a  (,
     and  all  subsequent  arguments  will  be  interpreted as an
     _e_x_p_r_e_s_s_i_o_n made up of the following primaries and operators.
     In  the  descriptions, wherever _n is used as a primary argu-
     ment, it will be 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:

     -atime _n        True if the file was accessed  _n  days  ago.
                    The  access  time  of  directories in _p_a_t_h is
                    changed by find itself.

     -cpio _d_e_v_i_c_e    Always true; write the current file on  _d_e_v_-
                    _i_c_e 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 directory
                    hierarchy to be done so that all entries in a
                    directory are acted on before  the  directory



SunOS 5.5.1          Last change: 1 Feb 1995                    1






find(1)                   User Commands                   find(1)



                    itself.  This can be useful when find is used
                    with cpio(1) to transfer files that are  con-
                    tained  in  directories without write permis-
                    sion.

     -exec _c_o_m_m_a_n_d   True if the executed _c_o_m_m_a_n_d returns a  zero
                    value  as  exit  status.   The end of _c_o_m_m_a_n_d
                    must be punctuated by an  escaped  semicolon.
                    A  command  argument  {}  is  replaced by the
                    current path name.

     -follow         Always true; causes  symbolic  links  to  be
                    followed.   When  following  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  sym-
                    bolic  link  pointed  to  an  ancestor.  This
                    expression should not be used with the - type
                    l expression.

     -fstype _t_y_p_e    True if the filesystem  to  which  the  file
                    belongs is of type _t_y_p_e.

     -group _g_n_a_m_e    True if the file belongs to the group _g_n_a_m_e.
                    If  _g_n_a_m_e  is  numeric and does not appear in
                    the /etc/group file, it is taken as  a  group
                    ID.

     -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.

     -ls            Always  true;  prints   current   path   name
                    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



SunOS 5.5.1          Last change: 1 Feb 1995                    2






find(1)                   User Commands                   find(1)



                    will instead contain the major and minor dev-
                    ice numbers.

                    If the file is a symbolic link  the  pathname
                    of  the linked-to file is printed preceded by
                    `->'.  The format is identical to that of  ls
                    -gilds (see ls(1)).

                    Note: Formatting is done internally,  without
                    executing the ls program.

     -mount          Always true; restricts  the  search  to  the
                    file  system  containing the directory speci-
                    fied.  Does not list mount  points  to  other
                    file systems.

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

     -name _p_a_t_t_e_r_n   True if _p_a_t_t_e_r_n  matches  the  current  file
                    name.   Normal  shell  file  name  generation
                    characters  (see  sh(1))  may  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.

     -ncpio _d_e_v_i_c_e   Always true; write the current file on  _d_e_v_-
                    _i_c_e in cpio -c format (5120 byte records).

     -newer _f_i_l_e     True if the current file has  been  modified
                    more recently than the argument _f_i_l_e.

     -nogroup        True if the file belongs to a group  not  in
                    the /etc/group file.

     -nouser         True if the file belongs to a  user  not  in
                    the /etc/passwd file.

     -ok _c_o_m_m_a_n_d     Like -exec except that the generated command
                    line  is  printed with a question mark first,
                    and is executed only if the user responds  by
                    typing y.

     -perm [-]_m_o_d_e    The _m_o_d_e argument is used to represent file
                    mode bits.  It will be identical in format to
                    the  <_s_y_m_b_o_l_i_cmode>  operand   described   in
                    chmod(1), and will be interpreted as follows.
                    To start, a template will be assumed with all
                    file mode bits cleared.  An _o_p symbol of:

                    +    will set the appropriate  mode  bits  in



SunOS 5.5.1          Last change: 1 Feb 1995                    3






find(1)                   User Commands                   find(1)



                         the template;

                    -     will clear the appropriate bits;

                    =    will  set  the  appropriate  mode  bits,
                         without  regard  to the contents of pro-
                         cess' file mode creation mask.

                    The _o_p symbol of - cannot be the first  char-
                    acter of _m_o_d_e; this avoids ambiguity with the
                    optional leading hyphen.  Since  the  initial
                    mode  is all bits off, there are not any sym-
                    bolic modes that need to use - as  the  first
                    character.

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

                    Otherwise, if _m_o_d_e is prefixed by  a  hyphen,
                    the primary will evaluate as true if at least
                    all the bits in the  resulting  template  are
                    set in the file permission bits.

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

     -print          Always true; causes the current path name to
                    be printed.

     -prune          Always yields  true.   Do  not  examine  any
                    directories  or files in the directory struc-
                    ture below the _p_a_t_t_e_r_n just matched.  See the
                    examples, below.

     -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,  l,  p, or f for block special
                    file, character special file, directory, sym-
                    bolic link, fifo (named pipe), or plain file,
                    respectively.

     -user _u_n_a_m_e     True if the file belongs to the user  _u_n_a_m_e.
                    If  _u_n_a_m_e is numeric and does not appear as a



SunOS 5.5.1          Last change: 1 Feb 1995                    4






find(1)                   User Commands                   find(1)



                    login name in the  /etc/passwd  file,  it  is
                    taken as a user ID.

     -xdev           Same as the -mount primary.

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

          1)   ( _e_x_p_r_e_s_s_i_o_n )      True  if   the   parenthesized
                                   expression       is       true
                                   (parentheses  are  special  to
                                   the    shell   and   must   be
                                   escaped).

          2)   ! _e_x_p_r_e_s_s_i_o_n        The negation of a  primary  (!
                                   is the unary _n_o_t operator).

          3)   _e_x_p_r_e_s_s_i_o_n [-a] _e_x_p_r_e_s_s_i_o_n
                                   Concatenation   of   primaries
                                   (the  _a_n_d operation is implied
                                   by the  juxtaposition  of  two
                                   primaries).

          4)   _e_x_p_r_e_s_s_i_o_n -o _e_x_p_r_e_s_s_i_o_n
                                   Alternation of primaries ( - o
                                   is the _o_r operator).

     Note:  When you use find in conjunction with  cpio,  if  you
     use  the  - L option with cpio then you must use the -follow
     expression with find and vice versa.  Otherwise  there  will
     be undesirable results.

     If no _e_x_p_r_e_s_s_i_o_n is present, -print  will  be  used  as  the
     expression.   Otherwise,  if  the  given expression does not
     contain any of the primaries -exec, -ok or -print, the given
     expression will be effectively replaced by:

          ( _g_i_v_e_n__e_x_p_r_e_s_s_i_o_n ) -print

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

EXAMPLES
     The following commands are equivalent:

          example% find .
          example% find . -print

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




SunOS 5.5.1          Last change: 1 Feb 1995                    5






find(1)                   User Commands                   find(1)



     Remove all files in your home directory 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 {} \;

     Recursively print all file names in  the  current  directory
     and below, but skipping SCCS directories:

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

     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

     The following command is roughly  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"
          fi

     The descriptions of -atime, -ctime, and -mtime use the  ter-
     minology   _n  ``24-hour  periods''.   For  example,  a  file
     accessed at 23:59 will be 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.

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

EXIT STATUS
     The following exit values are returned:
     0         All _p_a_t_h 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

SEE ALSO
     chmod(1),  ls(1),   sh(1),   test(1),   stat(2),   umask(2),



SunOS 5.5.1          Last change: 1 Feb 1995                    6






find(1)                   User Commands                   find(1)



     environ(5)

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

     -cpio _d_e_v_i_c_e   Always true; write the current file on _d_e_v_i_c_e
                    in cpio format (5120-byte records).

     -ncpio _d_e_v_i_c_e  Always true; write the current file on _d_e_v_i_c_e
                    in cpio -c format (5120 byte records).

NOTES
     When using find to determine files modified within  a  range
     of  time,  one must use the ?time argument _b_e_f_o_r_e the -print
     argument otherwise find will give all files.







































SunOS 5.5.1          Last change: 1 Feb 1995                    7



