Dit geeft de verschillen weer tussen de geselecteerde revisie en de huidige revisie van de pagina.
| — |
linux:commandos:metachar [2018/12/30 17:17] (huidige) |
||
|---|---|---|---|
| Regel 1: | Regel 1: | ||
| + | ====== Unix/Linux Metacharacters ====== | ||
| + | |||
| + | ===== FILE NAME GENERATION CHARACTERS: ===== | ||
| + | |||
| + | Will be interpreted by the **shell** **before** the command will be executed. The shell will look for matching file names in the current directory;the file name genera- tion characters on the command line will be replaced by the matching file names. | ||
| + | |||
| + | ? any single character except a leading dot (as in .exrc) | ||
| + | * zero or more characters except a leading dot | ||
| + | [ ] specifies one position in the file name | ||
| + | [0-9] inclusive range: one of the numbers 0-9 | ||
| + | [!0-9] exclusive range: any character but 0-9 | ||
| + | |||
| + | **Examples:** | ||
| + | |||
| + | $ echo .* all of the dotfiles in the current directory | ||
| + | $ echo ????? file names of 5 characters each, except dotfiles | ||
| + | $ echo [a-z][0-9]?.org file names of 7 characters each, starting with a | ||
| + | lower case letter and a number, ending with .org | ||
| + | $ ls -l f* long listing of file names starting with "f" | ||
| + | |||
| + | ===== QUOTING (used to prevent shell metacharacter interpretation): ===== | ||
| + | |||
| + | ' ' single quotes All metacharacters contained within single quotes | ||
| + | will lose their special meaning. | ||
| + | The shell won't interpret those metacharacters. | ||
| + | \ backslash The metacharacter after the backslash will lose | ||
| + | its special meaning. | ||
| + | " " double quotes All metacharacters contained within double quotes | ||
| + | will lose their special meaning except: | ||
| + | $variable, ${variable}, `cmd`, $(cmd), \ | ||
| + | This means that the shell will still perform | ||
| + | variable substitution and command substitution. | ||
| + | |||
| + | **Examples:** | ||
| + | |||
| + | $ PS1='$PWD $ ' prompt will show current value of PWD variable | ||
| + | $ find . -name f\* all file names with "f" in the current directory | ||
| + | $ echo "$TERM;$PATH" values of TERM and PATH variable separated by ";" | ||
| + | |||
| + | ===== REGULAR EXPRESSIONS (used to construct search patterns in applications): ===== | ||
| + | |||
| + | . any single character | ||
| + | * zero or more times the preceding character | ||
| + | a* zero or more times "a" | ||
| + | [ ] specifies one position in the search pattern | ||
| + | [abcd] one of the characters "a", "b", "c" or "d" | ||
| + | [A-Z] inclusive range: one upper case letter | ||
| + | [^A-Z] exclusive range: any character but A-Z | ||
| + | ^user the string "user" at the beginning of the line | ||
| + | user$ the string "user" at the end of the line | ||
| + | |||
| + | **Examples:** | ||
| + | |||
| + | $ grep '^user' /etc/passwd all lines starting with the string "user" | ||
| + | $ ps -ef | grep 'root' all processes of "root" | ||
| + | $ vi f1 | ||
| + | :1,10s/[Aa]nd/OR/g in lines 1 to 10 inclusively globally substitute | ||
| + | the string "And" or "and" by "OR" | ||
| + | |||
| + | Copyright (C) 2000 Integrated Services; tux4u.nl\\ Author: Drs.M.Waldorp-Bonk\\ metachar.html 20000708 | ||