Wednesday, May 28, 2008

Special Characters in Unix

A) The UNIX shell interprets a number of characters in special ways. These characters are most often used with UNIX commands - as arguments and for other means. The following list contains most of UNIX's special characters.

NEWLINE - initiates command execution
; - separates commands on same line
( ) - groups commands or identifies a function
& - executes a command in the background
| - pipe
> - redirects standard output
>> - appends standard output
< - redirects standard input * - wildcard for any number of characters in a file name ? - wildcard for a single character in a file name \ - quotes the following character ' - quotes a string preventing all substitutions " - quotes a string allowing variable and command substitution ` - performs command substitution [ ] - denotes a character class in a file name $ - references a variable { } - command grouping within a function . - executes a command (if at beginning of line) # - begins a comment : - null command B) Examples
-------------------

1. Use the * character in file names to match any number of characters. The following command:
ls *.txt

Will match the following files:
chapter1.txt doc.txt memo.txt a.txt
Will not match the following files:
doctxt txt.memo

2. Use the ? character in file names to match any single character. The following command:

ls ???.txt

Will match the following files:
one.txt doc.txt two.txt
Will not match the following files:
chap1.txt doctxt

3. Use the [ ] characters in file names to match any character within a range of characters. The following command:

ls chapter[1-3].txt

Will match the following files:
chapter1.txt chapter2.txt chapter3.txt
Will not match the following files:
chap1.txt chapter4.txt

If you want to know the details about these special characters then have a look at,

No comments:

Post a Comment