Google Your PC Using Find
find is an elaborate search program with a number of features. Unlike the Google Desktop Search and locate, it doesn’t index anything but processes the request on the fly. Thus it is slower.
find is one of the most useful commands when you also have to search within unknown files and make further operations on the result set. It does a recursive search, looking in all subdirectories.
The first set of arguments is always the paths where the search should initiate. $ find /home /tmp <remaining arguments> would search based on the remaining arguments in /home, /tmp and all their subdirectories. If unspecified, the default path is taken as ‘.’, the current working directory.
To search for a specific filename pattern, –name <regexp> is used as the next argument. $ find /home /tmp –name *.sh returns all .SH files present in /home, /tmp and their subdirectories.
Instead of piping, to perform any operation on each of the results returned, –exec is used. $ find /home /tmp –name *.sh –exec grep todo ‘{}’ \; –print searches for the string todo in the above returned files. grep does the search and ‘{}’ implies that all results need to be processed. The –print prints the final output, the actual lines containing the specified string in the files.
Instead of grep, it could be chmod or chown or any operation that can be done of files. These above options are the most common use cases of find.
There are a number of other options to refine the search like complex expressions with boolean operators, the maximum and minimum depth of subdirectories that need to be traversed, the modification times and permissions on files, the file types, etc. You can read about all these in the manual page.














