OPERATE ON THE RESULTS OF THE FIND COMMAND

Last time, we discussed some of the ways to search for files with the find command. The find command searches your hard drive for criteria that match the operations that are passed to it.

As a passive search tool, the find command works wonderfully. However, you can operate on the results of find as well, by passing it additional arguments. For example, assume that you want to find your editor's backup files in the current directory and its subdirectories that end with the tilda [~] character. Use this command:

$ find . -name '*~'

This will print the results in a list. If you want to remove these files, slightly change the argument:

$ find . -name '*~' -exec rm -i {} \;

Not only will this command find all files in the current directory and its subdirectories that end with ~, but it also removes each one by executing rm -i on the individual files. The { } sequence represents the files
that find returns and the \; sequence represents the end of the -exec argument.

Suppose that find reveals two files: text~ and subdir/testing~. This will produce the following end result:

rm -i text~
rm -i subdir/testing~

The find command is an ideal way to locate files and operate on them.
You can pass any argument to -exec, such as:

$ find . -name '*~' -exec ls -al {} \;

or:

$ find . -name '*~' -exec cat {} >>allbackups \;

The first command will produce a lengthy list of each found file, and the second will copy the contents of each found file into the file allbackups.

For a comprehensive list of the various options that are available for the find command, check out the find manpage.
http://www.linux.gr/cgi-bin/man2html/usr/share/man/man1/find.1.gz