Wildcard specification of filenames
Last revision August 3, 2004
Table of Contents: |
These apply to the C-shell. All but the tilde apply to the Bourne shell as well.
Certain special characters can be used as wildcards when typing filenames as part of commands. These wildcards can expand to or match several possible filenames. These expansions and matches are done by the shell, before it passes the argument list to the command, so they work the same for all commands that want filename arguments.
*
(asterisk) - matches any string of characters, including the null string. Example:
ls a*
matches any filename that starts with a, including just a
by itself.
?
(question mark) matches any single character. That is, it means any character
may be in its place, but there must be one, and only one, character there. Example:
ls a?b
matches any three-character filename that begins with a and ends
with b.
[...]
(list of characters enclosed in square brackets) matches any one
of the characters enclosed in the brackets. Example:
ls a[bcdefg]
matches any two-character filename that begins with a and ends with
either b or c or d , etc.
~
(tilde) is an abbreviation for home directory. By itself or just before the slash
character at the beginning of a pathname, it refers to the current user's home
directory. When used to prefix a user name, it refers to the home directory of
that specified user. Examples:
ls ~
shows all files in your home directory.
ls ~/prog
shows all files in the sub-directory prog in your home directory.
cd ~bruce
changes your working directory to be bruce's home directory.
<--Previous | Overview | |