Size: 1407
Comment: first-line; also expand to include simpler options
|
Size: 1350
Comment: rm -- *glob*
|
Deletions are marked like this. | Additions are marked like this. |
Line 8: | Line 8: |
rm *.bak *.old | rm -- *.bak *.old |
Line 14: | Line 14: |
rm *.{bak,old} | rm -- *.{bak,old} |
Line 17: | Line 17: |
If you need something still more general/powerful, in KornShell or [[BASH]] you can use ''extended globs''. In Bash, you'll need the {{{extglob}}} option to be set. It can be checked with: | If you need something still more general/powerful, in KornShell or [[BASH]] you can use [[glob|extended globs]]. In Bash, you'll need the {{{extglob}}} option to be set. It can be checked with: |
Line 40: | Line 40: |
For a more thorough explanation of extended globs, see [[glob]]. |
How can I use a logical AND/OR/NOT 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, there are a few options available.
If you want to operate on all the files that match glob A or glob B, just put them both on the same command line:
rm -- *.bak *.old
If you want to use a logical OR in just part of a glob (larger than a single charcter -- for which square-bracketed character classes suffice), in Bash, you can use BraceExpansion:
rm -- *.{bak,old}
If you need something still more general/powerful, in KornShell or BASH 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.