Next: , Previous: Scope, Up: Introduction



1.2 Overview

The principal programs used for making lists of files that match given criteria and running commands on them are find, locate, and 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 Kilobytes.

     find /usr/src -name '*.c' -size +100k -print

locate searches special file name databases for file names that match patterns. The system administrator runs the updatedb 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 administrator ran updatedb.

     locate '*[Mm]akefile'

The name xargs, pronounced EX-args, means “combine arguments.” 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 find. 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