find
Description: The "find" command is very powerful. It can search the entire filesystem for one or more files that you specify to look for. This is very helpful when a file has been "lost". You can also use the find command to locate files, and then perform some type of action on the files after they've been located. With this capability, you can locate files using powerful search criteria, and then run any Unix command you want on the files you locate. (See the examples below.)
Examples: find / -name Chapter1 -type f -print
This command searches through the root filesystem ("/") for the file named "Chapter1". If it finds the file, it prints the location to the screen.
find /usr -name Chapter1 -type f -print
This command searches through the "/usr" directory for the file named "Chapter1".
find /usr -name "Chapter*" -type f -print
This command searches through the "/usr" directory for all files that begin with the letters "Chapter". The filename can end with any other combination of characters.
This will match filenames such as "Chapter", "Chapter1", "Chapter1.bad", "Chapter_in_life".
find /usr/local -name "*.html" -type f -print
This command searches through the "/usr/local" directory for files that end with the extension ".html". These file locations are then printed to the screen.
find /usr/local -name "*.html" -type f -exec chmod 644 {} \;
This command searches through the "/usr/local" directory for files that end with the extension ".html". When these files are found, their permission is changed to mode 644 (rw-r--r--).
find htdocs cgi-bin -name "*.cgi" -type f -exec chmod 755 {} \;
This command searches through the "htdocs" and "cgi-bin" directories for files that end with the extension ".cgi". When these files are found, their permission is changed to mode 755 (rwxr-xr-x). This example shows that the find command can easily search through multiple sub-directories (htdocs, cgi-bin) at one time.