Difference between revisions 507892 and 507893 on knwiki

{{otheruses}}
{{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)

If running under Windows, don't include the backslash before the semicolon:

 find . -exec grep blah {} ;

If you will be executing over many results, it is more efficient to pipe the results to the [[xargs]] command instead.  xargs is a more modern implementation, and handles long lists in a more intelligent way.  The print0 option can be used with this.

The following command will ensure that filenames with whitespaces are passed to the executed COMMAND without being split up by the shell.  
It looks complicated at first glance, but is widely used.

 find . -print0 | xargs -0 COMMAND

The list of files generated by find (whilst it is being generated) is simultaneously [[Pipe_(Unix)|piped]] to xargs, which then executes COMMAND with the files as arguments.  See [[xargs]] for more examples and options.

===Search for a string===
This command will search for a string in all files from the /tmp directory and below:
(contracted; show full)[[fr:Find]]
[[it:Find (Unix)]]
[[hu:Find]]
[[ja:Find]]
[[pl:Find]]
[[pt:Find]]
[[ru:Find]]
[[fi:Find (Unix)]]