2.3.1 Base Name Patterns

Test: -name pattern
Test: -iname pattern

True if the base of the file name (the path with the leading directories removed) matches shell pattern pattern. For ‘-iname’, the match is case-insensitive.1 To ignore a whole directory tree, use ‘-prune’ (see Directories). As an example, to find Texinfo source files in /usr/local/doc:

find /usr/local/doc -name '*.texi'

Notice that the wildcard must be enclosed in quotes in order to protect it from expansion by the shell.

As of findutils version 4.2.2, patterns for ‘-name’ and ‘-iname’ match a file name with a leading ‘.’. For example the command ‘find /tmp -name \*bar’ match the file /tmp/.foobar. Braces within the pattern (‘{}’) are not considered to be special (that is, find . -name 'foo{1,2}' matches a file named foo{1,2}, not the files foo1 and foo2.

Because the leading directories are removed, the file names considered for a match with ‘-name’ will never include a slash, so ‘-name a/b’ will never match anything (you probably need to use ‘-path’ instead).


Footnotes

(1)

Because we need to perform case-insensitive matching, the GNU fnmatch implementation is always used; if the C library includes the GNU implementation, we use that and otherwise we use the one from gnulib