The principal programs used for making lists of files that match given
criteria and running commands on them are
xargs. An additional command,
updatedb, is used by
system administrators to create databases for
locate to use.
find searches for files in a directory hierarchy and prints
information about the files it found. It is run like this:
find [file…] [expression]
Here is a typical use of
find. This example prints the names
of all files in the directory tree rooted in /usr/src whose
name ends with ‘.c’ and that are larger than 100 KiB.
find /usr/src -name '*.c' -size +100k -print
Notice that the wildcard must be enclosed in quotes in order to protect it from expansion by the shell.
locate searches special file name databases for file names that
match patterns. The system administrator runs the
program to create the databases.
locate is run like this:
locate [option…] pattern…
This example prints the names of all files in the default file name
database whose name ends with ‘Makefile’ or ‘makefile’.
Which file names are stored in the database depends on how the system
xargs, pronounced EX-args, means “combine
xargs builds and executes command lines by
gathering together arguments it reads on the standard input. Most
often, these arguments are lists of file names generated by
xargs is run like this:
xargs [option…] [command [initial-arguments]]
The following command searches the files listed in the file file-list and prints all of the lines in them that contain the word ‘typedef’.
xargs grep typedef < file-list