find: Shell Pattern Matching
1
1 2.1.4 Shell Pattern Matching
1 ----------------------------
1
1 'find' and 'locate' can compare file names, or parts of file names, to
1 shell patterns. A "shell pattern" is a string that may contain the
1 following special characters, which are known as "wildcards" or
1 "metacharacters".
1
1 You must quote patterns that contain metacharacters to prevent the
1 shell from expanding them itself. Double and single quotes both work;
1 so does escaping with a backslash.
1
1 '*'
1 Matches any zero or more characters.
1
1 '?'
1 Matches any one character.
1
1 '[STRING]'
1 Matches exactly one character that is a member of the string
1 STRING. This is called a "character class". As a shorthand,
1 STRING may contain ranges, which consist of two characters with a
1 dash between them. For example, the class '[a-z0-9_]' matches a
1 lowercase letter, a number, or an underscore. You can negate a
1 class by placing a '!' or '^' immediately after the opening
1 bracket. Thus, '[^A-Z@]' matches any character except an uppercase
1 letter or an at sign.
1
1 '\'
1 Removes the special meaning of the character that follows it. This
1 works even in character classes.
1
1 In the 'find' tests that do shell pattern matching ('-name',
1 '-wholename', etc.), wildcards in the pattern will match a '.' at the
1 beginning of a file name. This is also the case for 'locate'. Thus,
1 'find -name '*macs'' will match a file named '.emacs', as will 'locate
1 '*macs''.
1
1 Slash characters have no special significance in the shell pattern
1 matching that 'find' and 'locate' do, unlike in the shell, in which
1 wildcards do not match them. Therefore, a pattern 'foo*bar' can match a
1 file name 'foo3/bar', and a pattern './sr*sc' can match a file name
1 './src/misc'.
1
1 If you want to locate some files with the 'locate' command but don't
1 need to see the full list you can use the '--limit' option to see just a
1 small number of results, or the '--count' option to display only the
1 total number of matches.
1