find
and locate
can compare file names, or parts of file
names, to shell patterns. A shell pattern is a string that may
contain the following special characters, which are known as
wildcards or metacharacters.
You must quote patterns that contain metacharacters to prevent the shell from expanding them itself. Double and single quotes both work; so does escaping with a backslash.
*
?
[
string]
\
In the find
tests that do shell pattern matching (-name,
-wholename, etc.), wildcards in the pattern will match a .
at the beginning of a file name. This is also the case for
locate
. Thus, find -name '*macs' will match a file
named .emacs, as will locate '*macs'.
Slash characters have no special significance in the shell pattern
matching that find
and locate
do, unlike in the shell, in
which wildcards do not match them. Therefore, a pattern foo*bar
can match a file name foo3/bar, and a pattern ./sr*sc can
match a file name ./src/misc.
If you want to locate some files with the locate command but don't need to see the full list you can use the --limit option to see just a small number of results, or the --count option to display only the total number of matches.