Difference between revisions 507988 and 507989 on knwiki

{{other uses}}
{{lowercase|title=find}} 
In [[Unix-like]] and some other [[operating system]]s, <code>'''find'''</code> is a [[command-line utility]] that [[Search engine (computing)|searches]] through one or more [[directory tree]]s of a [[file system]], locates [[Computer file|file]]s based on some [[user (computing)|user]]-specified criteria and applies a user-specified action on each matched file. The possible search criteria include a [[pattern matching|pattern(contracted; show full)Example of searching non-empty files.
 find . -not -size 0k

===Search files by name and size ===
 find /usr/src -not \( -name '*,v' -o -name '.*,v' \) '{}' \; -print 

This command will search in the /usr/src directory and all sub directories. All files that are of the form '*,v' and '.*,v' are excluded. Important arguments to note are:

       -not means the negation of the expression that follows
    \( means the start of a complex expression.
    \) means the end of a complex expression.
    -o means a logical or of a complex expression.
       In this case the complex expression is all files like '*,v' or '.*,v' 

 for file in `find /opt \( -name error_log -o -name 'access_log' -o -name 'ssl_engine_log' -o -name 'rewrite_log' -o
(contracted; show full)
This command searches files whose name has a prefix of "fileA_" or "fileB_" in the current directory.

 find . -name 'foo.cpp' -not -path '.svn'

This command searches for files with the name "foo.cpp" in all subdirectories of the current directory (current directory itself included) other than ".svn".


===Type filter explanation ===
Various type filters are supported by find, they are activated using the

 find -type c

configuration switch where c may be any of:
* '''b '''[[Device file|block (buffered) special]]
* '''c '''[[Device file|character (unbuffered special)]]
* '''d [[Directory (computing)|directory]]'''
* '''p '''[[Named pipe|named pipe (FIFO)]]
* '''f [[regular file]]'''
* '''l '''[[symbolic link]]; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. If you want to search for symbolic links when -L is in effect, use -xtype.
* '''s '''[[Unix domain socket|socket]]
* '''D '''[[Doors (computing)|door (Solaris)]]
(Bold listed configuration switches are most commonly used)
==See also==
*[[Locate_(Unix)|locate]], a Unix search tool based on a prebuilt database, and therefore it is faster and less accurate than <code>find</code> (because the database may not be up-to-date).
*[[mdfind]], a similar utility that utilizes metadata for [[Mac OS X]] and [[Darwin (operating system)|Darwin]]
*[[List of Unix programs]]
*[[List of DOS commands]]
*[[grep]]
*[[find (command)]], a DOS and Windows command that is very different from UNIX <code>find</code>
*[[findutils]]
*[[Tree (Unix)| tree]]

==External links==
*{{man|cu|find|SUS|find files}}
*{{man|1|find||search for files in a directory hierarchy}}
*[http://doc.cat-v.org/unix/find-history A story on the origins of the Unix find command].
*[http://www.gnu.org/software/findutils/ GNU Findutils] - Comes with the [[xargs]] and [[GNU locate|locate]] commands.
*[http://www.gnu.org/software/findutils/manual/html_mono/find.html Official webpage for GNU find]
*[http://www.softpanorama.org/Tools/Find/find_mini_tutorial.shtml Softpanorama find tutorial]
*[http://www.enciclopedia.galeon.com/find.html Exercises "Find"]
*[http://find.unixpin.com/ "Find helper" - unix "find" wizard]
*[http://www.oracle.com/technetwork/articles/calish-find-087766.html Guide to Linux Find Command Mastery]
*[http://www.shell-fu.org/lister.php?tag=find Top 'find' commands - interesting usage]

{{Unix commands}}

[[Category:Searching]]
[[Category:Standard Unix programs]]
[[Category:Unix SUS2008 utilities]]