Difference between revisions 508013 and 508014 on knwiki

{{other uses}}
{{unreferenced|date=September 2013}}
{{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(contracted; show full)

 find . -print0 | xargs -0 COMMAND

The list of files generated by <code>find</code> (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.

===Delete files and directories===

'''Caveats''': the -delete action is a GNU extension, and using it turns on -depth.   So, if you are testing a find command with -print instead of -delete in order to figure out what will happen before going for it, you need to use -depth -print.

Delete empty files and directories and print the names
 find /foo -empty -delete -print

Delete empty files
 find /foo -type f -empty -delete

Delete empty directories
 find /foo -type d -empty -delete
(contracted; show full)*{{man|1|find||search for files in a directory hierarchy}}
*[http://www.gnu.org/software/findutils/manual/html_mono/find.html Official webpage for GNU find]

{{Unix commands}}

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