Go to the first, previous, next, last section, table of contents.


Shell Pattern Matching

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.

*
Matches any zero or more characters.
?
Matches any one character.
[string]
Matches exactly one character that is a member of the string string. This is called a character class. As a shorthand, string may contain ranges, which consist of two characters with a dash between them. For example, the class `[a-z0-9_]' matches a lowercase letter, a number, or an underscore. You can negate a class by placing a `!' or `^' immediately after the opening bracket. Thus, `[^A-Z@]' matches any character except an uppercase letter or an at sign.
\
Removes the special meaning of the character that follows it. This works even in character classes.

In the find tests that do shell pattern matching (`-name', `-path', etc.), wildcards in the pattern do not match a `.' at the beginning of a file name. This is not the case for locate. Thus, `find -name '*macs'' does not match a file named `.emacs', but `locate '*macs'' does.

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'.


Go to the first, previous, next, last section, table of contents.