Penguin

Differences between current version and previous revision of Globs.

Other diffs: Previous Major Revision, Previous Author, or view the Annotated Edit History

Newer page: version 7 Last edited on Tuesday, May 1, 2007 6:14:03 pm by BenStaz
Older page: version 6 Last edited on Tuesday, May 1, 2007 5:48:28 pm by BenStaz Revert
@@ -1,29 +1,68 @@
-A File [Glob] is a way to match files. "*" matches any charactor . "?" matches any charactor exactly once. "[ [a-z]" matches any charactor in the range a-z. 
+A File [Glob] is a way to match files.  
+  
+* "*" matches any character .  
+* "?" matches any character exactly once.  
+* "~ [a-z~ ]" matches any character in the range a-z. 
  
 Some examples: 
  
- *.*  
- matches all files that contain a "." in them. 
+''~ *.*'' matches all files/dirs that contain a "." in them. 
  
- a*  
- matches all files that begin with a 
+'' a*'' matches all files/dirs that begin with a 
  
- [ [a-z]*  
- matches all files that begin with a lowercase letter 
+''~ [a-z~ ]*'' matches all files/dirs that begin with a lowercase letter 
  
- ~*.gz  
- matches all files that end with .gz 
+'' ~*.gz'' matches all files/dirs that end with .gz 
  
+''~[^A-C~]*'' matches all files/dirs that do not begin with A or B or C.  
+  
+<verbatim>  
 Note, * and ? __don't__ match / or a . at the beginning of a filename eg: * doesn't match: 
- .  
- ..  
- .foo  
- baz/nargle 
+  
+1) .foo  
+2) baz/nargle  
+  
 but does match: 
- foo.txt  
- baz/  
  
+1) foo.txt  
+2) baz/  
+</verbatim>  
+  
+!extglob  
+  
+This is a shell option that can be enabled by doing  
+  
+*shopt -s extglob  
+  
+Here are the extra pattern matching operators we can now use thanks to extglob:  
+<verbatim>  
+ ?(pattern-list)  
+ Matches zero or one occurrence of the given patterns  
+ *(pattern-list)  
+ Matches zero or more occurrences of the given patterns  
+ +(pattern-list)  
+ Matches one or more occurrences of the given patterns  
+ @(pattern-list)  
+ Matches one of the given patterns  
+ !(pattern-list)  
+ Matches anything except one of the given patterns  
+  
+pattern-list is just a bunch of globs separated by the | character.  
+</verbatim>  
+  
+  
+  
+  
+!extglob Examples  
+  
+<verbatim>  
+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.  
+  
+2) ls @(*foo*|*bar*|*car*) will list every file/directory that has either foo, bar or car in its name.  
+  
+3) mv file+([0-9]) /dest/dir/ will move every file/directory that has a prefix of ''file'' followed by at least one number.  
+</verbatim>  
  
 See glob(7) for more advanced uses. 
  
 Contrast RegularExpression.