Filename Metacharacters
Metacharacters |
Meaning |
|
Match any string of zero or more characters. |
|
Match any single character. |
|
Match any one of the enclosed characters; a hyphen can be used to specify a range (e.g., a-z, A-Z, 0–9). |
|
Match any character not enclosed as above. |
|
Expand each comma-separated string inside braces. The strings need not match actual filenames. |
|
Home directory for the current user. |
|
Home directory of user name. |
|
The nth entry in the directory stack, counting from zero. |
|
The last entry in the directory stack. |
|
Matches anything that
pattern does not match. To work
correctly, pattern must contain
|
Examples
%ls new*
Match new and new.1 %cat ch?
Match ch9 but not ch10 %vi
[D-R
]*
Match files that begin with uppercase D through R %ls {ch,app}?
Expand, then match ch1, ch2, app1, app2 %mv info{,.old}
Expands to mv info info.old %cd ~tom
Change to tom's home directory %touch aa bb cc
Create some files %ls ^a*
List nonmatching filenames bb cc
Tip
On modern systems, ranges such as [D-R]
are not portable; the system’s
locale may include more than just the uppercase letters from
D
to R
in the range.
Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.