| Rev | Author | # | Line |
|---|---|---|---|
| 7 | BenStaz | 1 | A File [Glob] is a way to match files. |
| 2 | |||
| 3 | * "*" matches any character. | ||
| 4 | * "?" matches any character exactly once. | ||
| 5 | * "~[a-z~]" matches any character in the range a-z. | ||
| 1 | PerryLorier | 6 | |
| 7 | Some examples: | ||
| 6 | BenStaz | 8 | |
| 7 | BenStaz | 9 | ''~*.*'' matches all files/dirs that contain a "." in them. |
| 1 | PerryLorier | 10 | |
| 7 | BenStaz | 11 | ''a*'' matches all files/dirs that begin with a |
| 1 | PerryLorier | 12 | |
| 7 | BenStaz | 13 | ''~[a-z~]*'' matches all files/dirs that begin with a lowercase letter |
| 1 | PerryLorier | 14 | |
| 7 | BenStaz | 15 | ''~*.gz'' matches all files/dirs that end with .gz |
| 4 | PerryLorier | 16 | |
| 7 | BenStaz | 17 | ''~[^A-C~]*'' matches all files/dirs that do not begin with A or B or C. |
| 18 | |||
| 19 | <verbatim> | ||
| 4 | PerryLorier | 20 | Note, * and ? __don't__ match / or a . at the beginning of a filename eg: * doesn't match: |
| 7 | BenStaz | 21 | |
| 22 | 1) .foo | ||
| 23 | 2) baz/nargle | ||
| 24 | |||
| 4 | PerryLorier | 25 | but does match: |
| 26 | |||
| 7 | BenStaz | 27 | 1) foo.txt |
| 28 | 2) baz/ | ||
| 29 | </verbatim> | ||
| 30 | |||
| 31 | !extglob | ||
| 32 | |||
| 33 | This is a shell option that can be enabled by doing | ||
| 34 | |||
| 35 | *shopt -s extglob | ||
| 36 | |||
| 37 | Here are the extra pattern matching operators we can now use thanks to extglob: | ||
| 38 | <verbatim> | ||
| 39 | ?(pattern-list) | ||
| 40 | Matches zero or one occurrence of the given patterns | ||
| 41 | *(pattern-list) | ||
| 42 | Matches zero or more occurrences of the given patterns | ||
| 43 | +(pattern-list) | ||
| 44 | Matches one or more occurrences of the given patterns | ||
| 45 | @(pattern-list) | ||
| 46 | Matches one of the given patterns | ||
| 47 | !(pattern-list) | ||
| 48 | Matches anything except one of the given patterns | ||
| 49 | |||
| 50 | pattern-list is just a bunch of globs separated by the | character. | ||
| 51 | </verbatim> | ||
| 52 | |||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | !extglob Examples | ||
| 57 | |||
| 58 | <verbatim> | ||
| 59 | 1) cp !(*.[Jj][Pp][Gg]|*.[Bb][Mm][Pp]) /dest/dir will copy every file to ''/dest/dir'' that is not a jpg or bmp file. | ||
| 60 | |||
| 61 | 2) ls @(*foo*|*bar*|*car*) will list every file/directory that has either foo, bar or car in its name. | ||
| 62 | |||
| 63 | 3) mv file+([0-9]) /dest/dir/ will move every file/directory that has a prefix of ''file'' followed by at least one number. | ||
| 64 | </verbatim> | ||
| 1 | PerryLorier | 65 | |
| 66 | See glob(7) for more advanced uses. | ||
| 67 | |||
| 5 | AristotlePagaltzis | 68 | Contrast RegularExpression. |
lib/blame.php:177: Warning: Invalid argument supplied for foreach()