BSD Apple OS X (Darwin) find

see GNU / Linux version
find walk a file hierarchy and display files matching a criteria or executing a command with the matching files as an argument.

find [-H | -L | -P] [-EXdsx] [-f pathname] [pathname …] expression

Recursively descends the directory tree for pathnames , evaluating an expression, composed of the primaries and operands in terms of each file in the tree.

Pressing ^t may be helpful when using find on a large directory tree with few matches.
Primaries which take a numeric argument allow a preceding plus (+) or minus (-).
+ means more than n,
- less than n and
  neither means equals n.
-P information for a symbolic link is of the link ( Pointer ). This is the default.
-L information of the file Linked to.
-H information for symbolic links         on the command are those of the files referenced by the link.
Information for symbolic links not on the command is that of the link .
If the referenced file does not exist, information will be for the link .
-E -regex and -iregex are extended regular expressions
-X names containing apostrophe ( ' ), quotes ( " ), backslash (\), space, tab and newline (which are delimiters used by xargs) are skippend and a diagnostic message is displayed on standard error.

-d
-depth
depth-first traversal, i.e., directories are visited in post-order and all entries in a directory will be acted on before the directory itself.
useful when used with cpio to process files that are contained in directories with various permissions. Enures write permission while placing files in a directory, then sets the directory's permissions .
Always true
d1
  f11
  d2
   f21
   f22  
  f2
order is f11, f21,f22,f2, d2, d1
By default, find visits directories in pre-order, i.e., before their contents.
the default is not a breadth-first traversal.

-f specifies a pathnames .
pathnames may also be specified as the operands following the options.

-s traverse the file hierarchies in lexicographical order, i.e., alphabetical order within each directory.
find -s and find | sort may give different results.

-x prevents descending into directories that have a device number different than that of the file from which the descent began.
eXclude volume crossing (as indicated by lindex directories)??

PRIMARIES

file time oriented

-Bmin m True if the difference between the file inode creation time and the time find was started, rounded up to the next full minute, is m minutes.
-Bnewer file Same as -newerBm.
-Btime n[smhdw] True if the difference between the file last access time and the time find was started, rounded up to the next full 24-hour period, is n 24-hour periods., or the time units smhdw Any number of units may be combined, for example, -Btime -1h30m. useful with + or -
-amin m True if the difference between the file last access time and the time find was started, rounded up to the next full minute, is m minutes.
-cmin m True if the difference between the time of last change of file status information and the time find was started, rounded up to the next full minute, is m minutes.

-cnewer file Same as -newercm.

-ctime n True if the difference between the time of last change of file status information and the time find was started, rounded up to the next full 24-hour period, is n 24-hour periods. , or the time units smhdw
-mmin m True if the difference between the file last modification time and the time find was started, rounded up to the next full minute, is m minutes.
-mtime d True if the difference between the file last modification time and the time find was started, rounded up to the next full 24-hour period, is d 24-hour periods.
-newer file True if the current file has a more recent last modification time than file.
-mnewer file Same as -newer.
-newercf file True if the
current file has a more recent access (a.)
change(c.)
or
modification(m.)
time than file's
access (.a)
change (.c)
or
modification (.m)
example: find . -neweram a.out
  • date (.t) file specifies a date of the form understood by cvs
  • -empty True if the current file or directory is empty.
    execution options
    -exec util [args…]\; True if util returns zero.

    The expression must be terminated by a semicolon (;) and escaped with a \.
    {} is replaced by the pathname of the current file.
    Utility will be executed from the directory from which find was executed.
    Utility and arguments are not subject to the further expansion of shell patterns and constructs.

    -execdir util args…] ;\ "as with exec " {} "… util will be executed from the directory that holds the current file
    -exec util args…] {} + " " {} is replaced with as many pathnames as possible for each invocation of util like xargs
    -ok utility [args …]\; As in the -exec additionally requests user affirmation for the execution of the utility by printing a message to the terminal and reading a response.
    y executes the command, anything else skips the command and returns false.
    /usr/bin/find . -iname "*~" -ok rm {} \;
    "rm ./Applications/Album/CHRIS.HTM~"? n
    "rm ./Documents/JackTheRiperCracker.html~"? n
    "rm ./Documents/main.java~"? y
    "rm ./Documents/MSU/585-01-security/Project/1-intro.txt~"? 
    -execdir utility [args…]\; Differes from -exec in that utility will be executed from the directory that holds the current file.
    The filename substituted for the string {} is not qualified.
    -perm [±]modeTests file permissions.
    mode may be symbolic (see chmod) or octal .

    -mmm true if   all bits in mmm are set in the file's mode bits.
    +mmm true if any bits in mmm are set in the file's .
     mmm true if the bits in mmm match the file's .
    If symbolic, a starting value of 000 and the mode sets or clears permissions (ignoring the process' file mode creation mask.
    If octal, only bits 07777 (SUID | SGID | STXT | U | G | O) of the file's mode bits participate in the comparison.
    i.e. q, zzz is ignored
    -flags [±]flags,notflags flags are specified using symbolic names (see chflags).
    Those with the "no" prefix are notflags (except nodump).
    flags are checked to be set
    notflags are checked to be reset.
    True if the bits in flags exactly match the file's flags bits, and none of the flags bits match those of notflags.

    - flags: true if at least all of the bits in flags and none of the bits in notflags are set in the file's flags bits.

    + flags: true if any of the bits in flags is set in the file's flags bits, or
    any of the bits in notflags is not set in the file's flags bits.

    Different from -perm, which only allows specifing permission bits(mode) that are set.

    -fstype type True if the file is type.
    sysctl displays the types of filesystems that are available

    sysctl vfs

    In addition, there are pseudo-types,

    • local matches any file system physically mounted on the system where the find is being executed and
    • rdonly matches any file system which is mounted read-only
    .
    -group gname True if the file belongs to the group gname.
    If gname is numeric and there is no such group name, then it is treated as a group ID.

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

    -maxdepth n True if the depth of the current file into the tree is less than or equal to n.
    -mindepth n pattern.
    Special shell pattern matching characters ([, ], *, and ?) may be used as part of pattern.
    These characters may be matched explicitly by escaping them with a backslash (\).
    -iname patternthe match is case insensitive.
    -nogroup True if the file belongs to an unknown group.
    -nouser True if the file belongs to an unknown user.

    -path pattern True if the pathname matches pattern.
    shell pattern matching characters ([, ], *, and ?) may be used as part of pattern, in which case the entire pattern should be enclosed in "
    To match these characters in the path escape them with a backslash (\).
    Slashes (/) are treated as normal characters and do not have to be matched explicitly.

    -ipath pattern Like -path, case insensitive.
    -regex pattern True if the whole path of the file matches pattern using regular expression.
    To match ./foo/xyzzy, use: .*/[xyz]* or .*/foo/.*,
    not xyzzy or /foo/.
    -iregex pattern Like -regex, but is case insensitive.
    -size n [ckMGTP] True if the file's size, rounded up, in 512-byte blocks is n, If n is followed by a
    c, size is characters, kilobytes, Mega, Giga, Tera, Peta.
    -type t True if the file is of the type.
    d directory c character special
    f regular file b block special
    l symbolic link
    p FIFO s socket
    -user uname True if the file belongs to the user uname. If uname is numeric and there is no such user name, then uname is treated as a user ID.
    primaries which are always true affect output
    -print Outputs the pathname of the current file to standard output. If none of -exec, -ls, -print0, or -ok is specified, the given expression shall be replaced by ( expression ) -print.
    -print0 Outputs the pathname of the current file followed NULL .
    Useful when filenames contain or spaces or other special characters espically with xargs
    -ls To STDOUT, The format is as per ls -dgils.
    inode  blks permissions hard owner group bytes modification  pathname
                            link
                           count
    1151651  32 -rwx------  1 userme mygrp   1638 May  9 2007 ./ds/archive/asts.xls
    3147130 360 -rwx------  1 userme mygrp  18278 Jan 27 2008 ./ds/asts-0801.xls
    3440935 552 -rwx------  1 userme mygrp  28006 Jul 13 2008 ./ds/asts-0807.xls
    2876708 368 -rwx------  1 userme mygrp  18585 Jan 21 2009 ./ds/asts-0810.xls
    4666431 360 -rwx------  1 userme mygrp  18380 Dec 20 2008 ./ds/asts-0812.xls
    9067172 528 -rwx------  1 userme mygrp  26828 Dec  9 2007 ./ds/asts-3yrs.xls
    9933738 664 -rwx------  1 userme mygrp  33689 Dec  9 2007 ./ds/asts-allyrs.xls 
    
    To removed everything before the bytes use:
    sed "s/^[[:digit:]]\{1,18\} \{1,9\}[[:digit:]]\{0,6\} .......... \{0,5\}[[:digit:]]\{0,4\} [[:alpha:]]\{1,7\}  [[:alpha:]]\{1,7\} //"
    For block or character special file, the major and minor numbers will be displayed .
    For symbolic link, the pathname of the linked-to file will be displayed preceded by ->.
    -delete Delete found files and/or directories.
    This executes from the current working directory as find recurses down the tree. It will not attempt to delete a filename with a / character in its pathname relative to . for security reasons.
    Depth-first traversal processing is implied by this option.
    -prune Don't descend into the current file.
    Ignored with -d (Depth first)
    -okdir utility i[argument ...i];
    -execdir primary with the same exception as described for the -ok primary.

    OPERATORS

    Primaries may be combined using these operators, listed in order of decreasing precedence.

    \( expression \) evaluates to true if the parenthesized expression evaluates to true.

    \! expression
    -false expression
    -not expression

    expression -and expression
    expression expression

    default opeator. The second expression is not evaluated if the first expression is false.

    expression -or expression The second expression is not evalated if the first expression is true.

    Operands and primaries must be separate arguments to find.
    Primaries which take arguments expect each argument to be a separate argument .

    Examples

    find mysrclib \! -name "*.c" -print names do not end in .c.

    find mysrclib -newer ttt -user wnj -print newer than ttt and owned by user wnj

    find mysrclib \! \( -newer ttt -user wnj \) -print are not both newer than ttt and owned by wnj.

    find mysrclib \( -newer ttt -or -user wnj \) -print either owned by wnj or newer than ttt.

    /usr/bin/find . -newerct '1 minute ago' -print whose inode change time is more recent than the current time minus one minute.

    See Also

    chflags, chmod, cvs, locate, whereis, which, stat, fts, getgrent, getpwent, strmode, re_format, psymlink .

    Standards

    Single character options as well as -iname, -inum, -iregex, -print0, -delete, -ls, and -regex are extensions to IEEE Std 1003.2 (POSIX.2).

    Historically -d, -h and -x were implemented using -depth, -follow, and -xdev.
    These are evaluated to true.
    As they were global variables that took effect before the traversal began, some legal expressions could have unexpected results.
    An example is the expression -print -o -depth.
    As -print always evaluates to true, the standard order of evaluation implies that -depth would never be evaluated. This is not the case.

    The -or was implemented as -o, and -and was implemented as -a.

    of the -exec and -ok did not replace {} in the utility name or the utility arguments if it had preceding or following non-whitespace characters. This version replaces it no matter where in the utility name or arguments it appears.

    The -E was implemented on the analogy of grep(1) and sed(1).

    BUGS The special characters used by find are also special characters to many shell programs. In particular, the characters *, [, ], ?, (, ), !, \ and ; may have to be escaped from the shell.

    As there is no delimiter separating options and file names or file names and the expression, it is difficult to specify files named -xdev or !. These problems are handled by the -f option and the getopt(3) -- construct.

    STANDARDS a superset of the syntax specified by the IEEE Std 1003.2 (POSIX.2) standard.
    single character options and -iname, -inum, -iregex, -print0, -delete, -ls, and -regex primaries are extensions to IEEE Std 1003.2 (POSIX.2).

    -d, -h and -x were implemented using the primaries -depth, -follow, and -xdev and evaluated true. As global variables that took effect before the traversal began, some expressions could have unexpected results. An example -print -o -depth. As -print evaluates to true, depth would not be evaluated. This is not the case.

    -or was implemented as -o, and the operator -and was implemented as -a.

    In some implementations -exec and -ok did not replace {} if it had preceding or following non-whitespace .
    This version replaces it whereever utility name or arguments .

    -E was implemented on the analogy of grep(1) and sed(1).

    Reminder: *, [, ], ?, (, ), !, \ and ; may have to be escaped from the shell.

    There is no delimiter separating options, names and expression, making it difficult to specify files named -xdev or !.
    Use -f and the getopt -- construct.

    -delete does not interact well with other options that cause the filesystem tree traversal options to be changed.

    -mindepth and -maxdepth are actually global options (as documented above). They should probably be replaced by options which look like options.

    BSD May 3, 2001 +2006