3.2 Globbing

Eshell’s globbing syntax is very similar to that of Zsh (see Filename Generation in The Z Shell Manual). Users coming from Bash can still use Bash-style globbing, as there are no incompatibilities.

By default, globs are case sensitive, except on MS-DOS/MS-Windows systems. You can control this behavior via the eshell-glob-case-insensitive option. You can further customize the syntax and behavior of globbing in Eshell via the Customize group eshell-glob (see Easy Customization in The GNU Emacs Manual).

*

Matches any string (including the empty string). For example, ‘*.el’ matches any file with the .el extension.

?

Matches any single character. For example, ‘?at’ matches cat and bat, but not goat.

**/

Matches zero or more subdirectories in a file name. For example, ‘**/foo.el’ matches foo.el, bar/foo.el, bar/baz/foo.el, etc. Note that this cannot be combined with any other patterns in the same file name segment, so while ‘foo/**/bar.el’ is allowed, ‘foo**/bar.el’ is not.

***/

Like ‘**/’, but follows symlinks as well.

[ … ]

Defines a character set (see Regexps in The GNU Emacs Manual). A character set matches characters between the two brackets; for example, ‘[ad]’ matches a and d. You can also include ranges of characters in the set by separating the start and end with ‘-’. Thus, ‘[a-z]’ matches any lower-case ASCII letter. Note that, unlike in Zsh, character ranges are interpreted in the Unicode codepoint order, not in the locale-dependent collation order.

Additionally, you can include character classes in a character set. A ‘[:’ and balancing ‘:]’ enclose a character class inside a character set. For instance, ‘[[:alnum:]]’ matches any letter or digit. See Char Classes in The Emacs Lisp Reference Manual, for a list of character classes.

[^ … ]

Defines a complemented character set. This behaves just like a character set, but matches any character except the ones specified.

( … )

Defines a group. A group matches the pattern between ‘(’ and ‘)’. Note that a group can only match a single file name component, so a ‘/’ inside a group will signal an error.

x|y

Inside of a group, matches either x or y. For example, ‘e(m|sh)-*’ matches any file beginning with em- or esh-.

x#

Matches zero or more copies of the glob pattern x. For example, ‘fo#.el’ matches f.el, fo.el, foo.el, etc.

x##

Matches one or more copies of the glob pattern x. Thus, ‘fo#.el’ matches fo.el, foo.el, fooo.el, etc.

x~y

Matches anything that matches the pattern x but not y. For example, ‘[[:digit:]]#~4?’ matches 1 and 12, but not 42. Note that unlike in Zsh, only a single ‘~’ operator can be used in a pattern, and it cannot be inside of a group like ‘(x~y)’.