next up previous contents
Next: World Wide Web and Up: Essential Topics Previous: Restoring Deleted Files   Contents


Shell Metacharacters

There are a number of characters that have special meaning to the shell, which is what makes them metacharacters. Note that meta- is a generic prefix assuming different meanings for different programs. Be careful not to confuse their meanings or confuse them with metakeys. Common tcsh metacharacters are (! $ ^ & * ( ) ~ [ ] $\backslash$ | { } ' " ; < > ? [space] [tab]). The metacharacters are explained further in the man page for tcsh. Table [*] contains very commonly used metacharacters.


Table: Common Metacharacters
Metacharacter Function
; seperates multiple commands on the same line
? matches any one character in a file name
  matches zero or more characters in a file name
& runs the preceding command in the background
$\backslash$ nullifies the special meaning of the next metacharacter


As an example,

[bbadger@demo01] (1)$ ls file.*

run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,

[bbadger@demo01] (1)$ ls file.?

run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with `c', you could view the file without typing the whole name by typing this:

[bbadger@demo01] (1)$ more c*

because the c* matches that long file name.

Filenames containing metacharacters can pose many problems and should never be intentionally created. If you do find that you've created a file with metacharacters, and you would like to remove it, you have three options. You may use wildcards to match metacharacter, use the $\backslash$ to directly enter the filename, or put the command in double quotes (except in the case of double quotes within the file name, these must be captured with one of the first two methods). For example, deleting a file named `*|more' can be accomplished with:

[bbadger@demo01] (1)$ rm ??more

or

[bbadger@demo01] (1)$ rm $\backslash$*$\backslash$|more

or

[bbadger@demo01] (1)$ rm ``*|more''


next up previous contents
Next: World Wide Web and Up: Essential Topics Previous: Restoring Deleted Files   Contents
Michelle Craft 2008-01-23