Psych 770u

Unix Tools for Behavioral Research

Special Characters

The following characters all have special uses or meanings in UNIX (some have special names)

! @ $ ^ & * ~ ? . | / [ ] < > \ ` " ;# ( )


For now lets consider * ? and [ ].

Unix offers powerful 'wildcard' operations which allow one to type in only the unique portion of a filename and then substitute a "multiple character wildcard" '*' for the rest.

If only a single character needs to be substituted for then a '?' is used.

lists all files starting with AX (including AX)

lists all three-letter file names starting with AX (but won't list a file called AX).

[ ] is used to define a set to allow the substitution of a single character from a class of alpha-numeric characters.

Any string of characters within [ ] are treated as the class of characters to substitute for.

Unix recognizes continuous series of letters or numbers so that [1-9] or [a-z] represent the digits one through nine and all lowercase letters.

The series [a-zA-Z] represents all letters. However, because of the way characters are generated [a-Z] doesn't represent all letters. Instead it represents the set "a, -, Z".

If two sets are placed side by side then there is substitution for two characters meeting the conditions of both sets. (eg [a-z][A-Z] will substitute for any lowercase letter followed by any uppercase letter).


What if you want to use one of these characters in a file name?

(First of all DON'T), but there is a way of telling UNIX that you want to abort the special nature of these characters.

The '\' character says that the single character that follows is to be treated as a literal. Thus '\*' loses its special meaning and just becomes a splat.

This "\ " followed by a single character is refered to as an escape sequence.

When in doubt you can always escape a character with a backslash. Note this is not a '/', but a '\'.


What are these other special characters used for?

Not all of the special characters are described here; just the ones you need to regularly know.

# Comments - in a shell script (program) everything after the # is ignored

^ means START(used to indicate the start of a line)

$ means END

example: ls | grep X$ (find all files ending with X)

$ also indicates1

! means NOT

" is weak quote

' is strong quote


Unix Character Names

! This isn't an exclamation point, it's a "bang". Return

^ Nope, this isn't a carat, it's a "hat". Return

* You may have thought this is an asterisk, but it's not. It's a "splat". Return

. This is a "dot", not a period. Return

| This is a "pipe" not whatever it is really called (a semi-flat?). Return

/ When the top tips to the right it's a "slash". Return

\ When the top tips to the left it's a "backslash" Return


Alpha-numeric means the set of all typable characters (a-z, A-Z, 0-9, punctuation). Return

Return to Home