Differences between revisions 1 and 2
Revision 1 as of 2007-05-02 23:01:34
Size: 722
Editor: redondos
Comment:
Revision 2 as of 2007-12-13 21:06:11
Size: 854
Editor: GreyCat
Comment: more on globs, including link
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
That can be achieved through the !() extglob operator. You'll need {{{extglob}}} 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 the !() extglob operator. You'll need {{{extglob}}} set. It can be checked with:

Anchor(faq16)

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

[: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 the !() extglob operator. You'll need extglob 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

For the general case:

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 KornShell and KornShell93, too. They don't have to be enabled there, but are the default patterns.

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