Differences between revisions 3 and 4
Revision 3 as of 2008-05-08 23:58:22
Size: 936
Editor: GreyCat
Comment: clean up
Revision 4 as of 2008-11-22 14:09:45
Size: 937
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[[Anchor(faq16)]] <<Anchor(faq16)>>
Line 4: Line 4:
[:glob:"Globs"] are simple patterns that can be used to match filenames or strings. They're generally not very powerful. If you need more power, you can use ''extended globs''. In [:BASH:], you'll need the {{{extglob}}} option to be set. It can be checked with: [[glob|"Globs"]] are simple patterns that can be used to match filenames or strings. They're generally not very powerful. If you need more power, you can use ''extended globs''. In [[BASH]], you'll need the {{{extglob}}} option to be set. It can be checked with:
Line 27: Line 27:
For a more thorough explanation of extended globs, see [:glob:]. For a more thorough explanation of extended globs, see [[glob]].

How can I use a logical AND in a shell pattern (glob)?

"Globs" are simple patterns that can be used to match filenames or strings. They're generally not very powerful. If you need more power, you can use extended globs. In BASH, you'll need the extglob option to be set. It can be checked with:

$ shopt extglob

and set with:

$ shopt -s extglob

To warm up, we'll move all files starting with foo AND not ending with .d to directory foo_thursday.d:

$ mv foo!(*.d) foo_thursday.d

A more complex example -- delete all files containing Pink_Floyd AND not containing The_Final_Cut:

$ rm !(!(*Pink_Floyd*)|*The_Final_Cut*)

By the way: these kind of patterns can be used with the KornShell, too. They don't have to be enabled there, but are the default patterns.

For a more thorough explanation of extended globs, see glob.

BashFAQ/016 (last edited 2015-03-05 00:31:02 by izabera)