The find command allows the Unix user to process a set of files and/or directories in a file subtree.
You can specify the following:
find . -name "rc.conf" -print
This command will search in the current directory and all sub directories for a file named rc.conf.
Note: The -print option will print out the path of any file that is found with that name. In general -print wil print out the path of any file that meets the find criteria.
find . -name "rc.conf" -exec chmod o+r '{}' \;
This command will search in the current directory and all sub directories. All files named rc.conf will be processed by the chmod -o+r command. The argument '{}' inserts each found file into the chmod command line. The \; argument indicates the exec command line has ended.
The end results of this command is all rc.conf files have the other permissions set to read access (if the operator is the owner of the file).
find /usr/src -not \( -name "*,v" -o -name ".*,v" \) '{}' \; -print
This command will search in the /usr/src directory and all sub directories. All files that are of the form '*,v' and '.*,v' are excluded. Important arguments to note are:
The above example is shows how to select all file that are not part of the RCS system. This is important when you want go through a source tree and modify all the source files... but ... you don't want to affect the RCS version control files.
find . -exec grep "www.utm" '{}' \; -print
This command will search in the current directory and all sub directories. All files that contain the string will have their path printed to standard output.
If you want to just find each file then pass it on for processing use the -q grep option. This finds the first occurrence of the search string. It then signals success to find and find continues searching for more files.
find . -exec grep -l "www.utm" '{}' \; -print -- note that this works on Solaris; it is -q on other Unix versions
This command is very important for process a series of files that contain a specific string. You can then process each file appropriately. An example is find all html files with the string "www.utm.edu". You can then process the files with a sed script to change those occurrances of "www.utm.edu" with "www1.utm.edu".
dbloodworth@utm.edu -- This page was last modified on Feb 25, 2005 by CDB.