Difference between revisions 507992 and 507993 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) find . -size +100k -a -size -500k
Example of searching empty files.
 find . -size 0k
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' {{abbr|-not|the negation of the expression that follows}} {{abbr|\(|the start of a complex expression.}} -name '*,v' {{abbr|-o|a logical or of a complex expression. In this case the complex expression is all files like '*,v' or '.*,v'}} -name '.*,v' {{abbr|\)|the end of a complex expression.}} '{}' \; -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 in the [[tooltip]] that is displayed on mouse-over.

<source lang="bash" enclose="div">
 for file in `find /opt \( -name error_log -o -name 'access_log' -o -name 'ssl_engine_log' -o -name 'rewrite_log' -o
 -name 'catalina.out' \) -size +300000k -a -size -5000000k`; do cat /dev/null > $file; done
</source>
(contracted; show full)*[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]]