Difference between revisions 507768 and 507769 on knwiki

{{lowercase|title=find}} 
:''For the EP by Hidden in Plain View, see [[Find (EP)]]''

The <code>'''find'''</code> program is a [[search utility]], mostly found on [[Unix-like]] platforms. It searches through a [[directory (file systems)|directory]] [[tree (computing)|tree]] of a [[filesystem]], locating [[Computer file|file]]s based on some user-specified criteria. By default, <code>find</code> returns all files below the current [[wo(contracted; show full)uted replacing <code>{}</code> with the name of the file. The semicolon (backslashed to avoid the shell interpreting it as a command separator) indicates the end of the command. Permission <code>744</code>, usually shown as <code>rwxr--r--</code>, gives the file owner full permission to read, write, and execute the file, while other users have read-only access.

===Search for a string===
This command will search for a string in all files from the /tmp directory and below
. :

 find /tmp -exec grep "search string" '{}' /dev/null \; -print

The <tt>[[/dev/null]]</tt> argument is used to show the name of the file before the text that is found. Without it, only the text found is printed.  An equivalent mechanism is to use the "-H" or "--with-filename" option to grep:

 find /tmp -exec grep -H "search string" '{}' /dev/null \; -p\; -print

GNU grep can be used on its own to perform this task:

 grep -R /tmp "search strintg"

Example of search for "LOG" in jsmith's home directory
 find ~jsmith -exec grep "LOG" '{}' /dev/null \; -print
 /home/jsmith/scripts/errpt.sh:cp $LOG $FIXEDLOGNAME
 /home/jsmith/scripts/errpt.sh:cat $LOG
 /home/jsmith/scripts/title:USER=$LOGNAME

Example of search for the string "ERROR" in all xml files in the current directory and all sub-directories
 find . -name "*.xml" -exec grep "ERROR" '{}' \; -print

The double quotes (" ") surrounding the search string and single quotes (<nowiki>' '</nowiki>) surrounding the braces are optional in this example, but needed to allow spaces and other special characters in the string.

==See also==

* [[searchmonkey]], an alternative search tool using the [[Gtk]] front-end

==External links==
* [http://www.gnu.org/software/findutils/ GNU Findutils] - Comes with the [[xargs]] and [[locate]] commands.
* [http://www.gnu.org/software/findutils/manual/html_mono/find.html Official webpage for GNU find]
* [http://www.linuxmanpages.com/man1/find.1.php Linux find(1)] [[manpage]]
* [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Unix man page]

{{unix commands}}

[[Category:Unix software]]
[[Category:Searching]]

[[de:Find]]
[[pl:Find]]