Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ find(1) — AIX/RT 2.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

cpio

sh

test

stat

cpio

fs

find

PURPOSE

     Finds files matching expression.

SYNOPSIS
     find path-name ... expression


DESCRIPTION

     The find command recursively  searches the directory tree
     for  each  specified path,  seeking  files  that match  a
     Boolean expression  written using the terms  given below.
     The  output  from  find  depends on  the  terms  used  in
     expression.

EXPRESSION TERMS

     In  the following  descriptions, the  parameter num  is a
     decimal integer that can be  specified as +num (more than
     num), -num (less than num), or num (exactly num).

     -inum  n          True if file has inode n.
     -name  file       True  if file  matches  the file  name.
                       You  can  use pattern-matching  charac-
                       ters, provided they  are quoted.  In an
                       expression  such  as [a-z],  the  minus
                       means   "through"   according  to   the
                       current  collating  sequence.   A  col-
                       lating sequence  may define equivalence
                       classes  for use  in character  ranges.
                       See  "Overview  of International  Char-
                       acter  Support"  in  Managing  the  AIX
                       Operating  System for  more information
                       on collating  sequences and equivalence
                       classes.
     -node nname       True if  the file  resides in  the node
                       nname.  If  nname is a  valid nickname,
                       it is  used as is.   If nname is  not a
                       valid  nickname  but  has a  valid  NID
                       syntax, it is used as a NID.
     -perm  onum       True if the file permission code of the
                       file exactly  matches the  octal number
                       onum (see "chmod" for an explanation of
                       file permissions).   The onum parameter
                       may be  up to  three octal  digits.  If
                       you want to  test the higher-order per-
                       mission  bits (the  set-user-ID bit  or
                       set-group-ID bit,  for example), prefix
                       the  onum parameter  with  a minus  (-)
                       sign.  This  makes more flag  bits sig-
                       nificant (see the  stat system call for
                       an explanation of the additional bits),
                       and also changes the comparison to:

                       (flags"&"onum)==onum

     -type  type       True if the file  type is of the speci-
                       fied type as follows:
                       b  Block special file
                       c  Character special file
                       d  Directory
                       f  Plain file
                       p  FIFO (a named pipe).
     -links  num       True if  the file  has num  links.  See
                       "ln."
     -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
                       /etc/passwd file, it  is interpreted as
                       a user ID.
     -group  gname     True if  the file belongs to  the group
                       gname.   If gname  is numeric  and does
                       not appear  in the /etc/group  file, it
                       is interpreted as a group ID.
     -size  num        True  if the  file is  num blocks  long
                       (512 bytes  per block).  For  this com-
                       parison the file size  is rounded up to
                       the nearest block.
     -atime  num       True if  the file has been  accessed in
                       num days.
     -mtime  num       True if  the file has been  modified in
                       num days.
     -ctime  num       True  if  the   file  i-node  has  been
                       changed in num days.
     -exec  cmd        True if the cmd runs and returns a zero
                       value as  exit status.  The end  of cmd
                       must  be  punctuated  by  a  quoted  or
                       escaped semicolon.  A command parameter
                       "{}"  is replaced  by the  current path
                       name.
     -ok  cmd          The  find command  asks you  whether it
                       should  start  cmd.  If  your  response
                       begins with  "y", cmd is  started.  The
                       end  of cmd  must  be  punctuated by  a
                       quoted or escaped semicolon.
     -print            Always  true; causes  the current  path
                       name  to be  displayed.  find  does not
                       display path  names unless  you specify
                       this expression term.
     -cpio  device     Write  the current  file  to device  in
                       cpio format.  See "cpio."
     -newer  file      True if the current file has been modi-
                       fied more recently  than the file indi-
                       cated by file.
     -depth            Always true.   This causes  the descent
                       of the  directory hierarchy to  be done
                       so that all entries  in a directory are
                       affected  before the  directory itself.
                       This can  be useful  when find  is used
                       with  cpio to  transfer files  that are
                       contained in  directories without write
                       permission.
     \( expression \)  True if  the expression  in parentheses
                       is true.

     You may perform the following logical operations on these
     terms (listed in order of decreasing precedence):

     o   Negate a term (! is the NOT operator).
     o   Concatenate terms (juxtaposing  two terms implies the
         AND operation).
     o   Alternate terms (-o is the OR operator).

EXAMPLES

     1.  To list  all files  in the file  system with  a given
         base file name:

           find  /  -name  .profile  -print

         This searches  the entire file system  and writes the
         complete path  names of  all files  named ".profile".
         The "/" tells  find to search the  root directory and
         all of its subdirectories.  This may take a while, so
         it  is best  to limit  the search  by specifying  the
         directories where you think the files might be.
     2.  To list the files with  a specific permission code in
         the current directory tree:

           find  .  -perm  0600  -print

         This  lists the  names of  the files  that have  only
         owner-read and owner-write permission.  The "." (dot)
         tells find  to search  the current directory  and its
         subdirectories.  See  "chmod" for details  about per-
         mission codes.
     3.  To search several directories  for files with certain
         permission codes:

           find  manual  clients  proposals  -perm  -0600  -print

         This lists  the names of  the files that  have owner-
         read  and owner-write  permission and  possibly other
         permissions.   The  directories "manual",  "clients",
         and  "proposals",   and  their   subdirectories,  are
         searched.   Note that  "-perm 0600"  in the  previous
         example selects only files with permission codes that
         match "0600" exactly.  In this example, "-perm -0600"
         selects  files with  permission codes  that allow  at
         least the  accesses indicated  by "0600".   This also
         matches the permission codes "0622" and "2744".
     4.  To search for regular files with multiple links:

           find  .  -type  f  -links  +1  -print

         This lists  the names  of the ordinary  files ("-type
         f") that have more than one link ("-links +1").  Note
         that  every directory  has at  least two  links:  the
         entry in its  parent directory and its  own "." (dot)
         entry.   See "ln"  for  details  about multiple  file
         links.
     5.  To back up selected files in cpio format:

           find  .  -name  "*.c"  -cpio  /dev/rfd0

         This saves  all the ".c"  files onto the  diskette in
         cpio format.  See "cpio"  for details.  Note that the
         pattern ""*.c""  must be quoted to  prevent the shell
         from treating the *  as a pattern-matching character.
         This is a  special case in which  find itself decodes
         the pattern-matching characters.
     6.  To perform an  action on all files  that meet complex
         requirements:

           find . \( -name a.out -o -name "*.o" \) -atime +7 -exec rm {} \;

         This  deletes  ("-exec rm  {}  \;")  all files  named
         "a.out" or  that end  with ".o",  and that  were last
         accessed over seven days ago ("-atime +7").  The "-o"
         flag is the logical OR operator.

FILES

     /etc/group   File that contains all known groups.
     /etc/passwd  File that contains all known users.

RELATED INFORMATION

     The following commands:  "cpio,"  "sh," and "test."

     The stat  system call and  the cpio  and fs files  in AIX
     Operating System Technical Reference.

     "Overview of International  Character Support" and "Using
     Distributed  Services"  in  Managing  the  AIX  Operating
     System.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026