find
The find command, unlike locate, performs a live search of your file system. It is very versatile, and can search by filename, owner, last modified time, and other criteria. Its syntax is:
find starting_directory –criteria search_string
The starting directory can be any location, with a relative or absolute path. In other words, /etc will get you to /etc, ../ will take you up one directory, mydirectory/ is a subdirectory, . is the current directory, and so forth, exactly as you’re accustomed to doing.
Criteria can be a user’s name, the file name, and more:
For example:
Find owned by a particular user:
find /var -user root
Will find every file under the directory /var owned by the user root.find /bin -name *.sh
Will find every file under the directory /bin ending in “.sh”.find /var/spool -mtime +10
Will find every file in /var/spool last modified more than 10 days ago.
Now’s a good time to take a look at the idea of Order of Operations. You’re going to need it to understand something about using wildcards with the find command. Newer versions of find have no trouble with:
find /etc -name host*
Older versions, however, will hiccup over the wildcard, because the shell will “get to” the wildcard, and interpret it, before the find command is run. You have to quote the wildcard for things to work right:
find /etc -name “host*”
Finally: never be reluctant to run man find.