For questions pertaining to find, a command-line utility to search for files in a directory hierarchy. Use this tag for questions about find itself or questions about issues arising from using the find command-line utility.

find is a utility to search a directory tree for objects (files and/or directories) matching certain criteria (name, type, date, …) and print their names or perform actions on them.

The find command is invoked like

find [options] [starting-point...] [expression]

starting-point is one or more paths (absolute or relative directories). These are the places where find will start to look for files. The default starting point is the current directory .

expression is zero or more of: tests and actions (and some other types).

  • Tests are used to filter the set of files you want to act upon. You can filter on types of files, filename patterns, file attributes, and so on.
  • Actions are things you want to do with the files. The default action is to print the path to the file. You can specify multiple actions. Some actions are:
    • -exec -- send the filenames as arguments to some program,
    • -ls -- list them like ls -l
    • -printf -- print out your choice of attributes about the files
    • -delete -- make sure before you delete your files that you know which files will be found! -print them first.

Common idioms

List all the regular files in the current directory and its subdirectories:

find . -type f

Same, but do not recurse into directories called .svn:

find . -type d -name .svn -prune -o -type f -print

Recode all *.txt files in the current directory and its subdirectories from latin1 to utf8 (two equivalent commands):

find . -type f -name '*.txt' -exec recode latin1..utf8 {} +
find . -type f -name '*.txt' -print0 | xargs -0 recode latin1..utf8

Further reading

External references