pavement

Find

From FreeBSDwiki
Revision as of 13:34, 22 February 2005 by Dave (Talk | contribs)
Jump to: navigation, search

Used to find files or directories. For bare-bones help in finding a particular file or directory, use in conjunction with the -name argument:

samizdata# find / -name "string"

will execute find on / and then only show you the results that match "string". Note that this is not a fast search and can take a very long time and burn a lot of system resources when used on large (or multiple) filesystems - in this example, every single device and filesystem on the machine will be groveled over directly looking for anything with "string" in the filename. If you knew that the file you wanted to find was in a user's home directory, for example, you would be much better off with the following:

samizdata# find /usr/home -name "string"

With the above, you won't waste time and valuable system resources thrashing all hard drives looking for a file you know can't be anywhere other than /usr/home. If you're receiving too many results and you want to narrow them down somewhat, you can pipe the results through grep for easier review - let's say you're looking for a file that contains "string", and you also know it contains "silly", but you don't know whether it's "sillystring" or "string,silly" or "silly_string" or... you get the idea. Try this:

samizdata# find /usr/home -name "string" | grep "silly"

Still getting more results than fit on the screen at once? Pipe it through more:

samizdata# find /usr/home -name "string" | grep "silly" | more

Even after all this, we've barely scratched the surface of what you can do with find - it's a complicated beast that is well worth the time spent in investigating further via the man pages.

See also locate for a far more optimized method of searching for files by substring, using a database generated by the weekly periodic routines rather than a brute-force search of the filesystem itself.

Personal tools