Next: , Previous: , Up: Name   [Contents][Index]

2.2.2 Full Name Patterns

Test: -path pattern
Test: -wholename pattern

True if the entire file name, starting with the command line argument under which the file was found, matches shell pattern pattern. To ignore a whole directory tree, use ‘-prune’ rather than checking every file in the tree (see Directories). The “entire file name” as used by find starts with the starting-point specified on the command line, and is not converted to an absolute pathname, so for example cd /; find tmp -wholename /tmp will never match anything.

Find compares the ‘-path’ argument with the concatenation of a directory name and the base name of the file it’s considering. Since the concatenation will never end with a slash, ‘-path’ arguments ending in ‘/’ will match nothing (except perhaps a start point specified on the command line).

The name ‘-wholename’ is GNU-specific, but ‘-path’ is more portable; it is supported by HP-UX find and is part of the POSIX 2008 standard.

Test: -ipath pattern
Test: -iwholename pattern

These tests are like ‘-wholename’ and ‘-path’, but the match is case-insensitive.

In the context of the tests ‘-path’, ‘-wholename’, ‘-ipath’ and ‘-wholename’, a “full path” is the name of all the directories traversed from find’s start point to the file being tested, followed by the base name of the file itself. These paths are often not absolute paths; for example

$ cd /tmp
$ mkdir -p foo/bar/baz
$ find foo -path foo/bar -print
$ find foo -path /tmp/foo/bar -print
$ find /tmp/foo -path /tmp/foo/bar -print

Notice that the second find command prints nothing, even though /tmp/foo/bar exists and was examined by find.

Unlike file name expansion on the command line, a ‘*’ in the pattern will match both ‘/’ and leading dots in file names:

$ find .  -path '*f'
$ find .  -path '*/*config'
Test: -regex expr
Test: -iregex expr

True if the entire file name matches regular expression expr. This is a match on the whole path, not a search. For example, to match a file named ./fubar3, you can use the regular expression ‘.*bar.’ or ‘.*b.*3’, but not ‘f.*r3’. See Syntax of Regular Expressions in The GNU Emacs Manual, for a description of the syntax of regular expressions. For ‘-iregex’, the match is case-insensitive.

As for ‘-path’, the candidate file name never ends with a slash, so regular expressions which only match something that ends in slash will always fail.

There are several varieties of regular expressions; by default this test uses POSIX basic regular expressions, but this can be changed with the option ‘-regextype’.

Option: -regextype name

This option controls the variety of regular expression syntax understood by the ‘-regex’ and ‘-iregex’ tests. This option is positional; that is, it only affects regular expressions which occur later in the command line. If this option is not given, GNU Emacs regular expressions are assumed. Currently-implemented types are


Regular expressions compatible with GNU Emacs; this is also the default behaviour if this option is not used.


Regular expressions compatible with the POSIX awk command (not GNU awk)


POSIX Basic Regular Expressions.


Regular expressions compatible with the POSIX egrep command


POSIX Extended Regular Expressions

Regular Expressions for more information on the regular expression dialects understood by GNU findutils.

Next: , Previous: , Up: Name   [Contents][Index]