In my shell bash, I have to select files beginning by ab
or xyz
and don't end by .jpg
or .gif
here is what i did but it doesn't work:
$ echo ab*[!.jpg] ab*[!.gif] xyz*[!.jpg] xyz*[!.gif]
With bash's extended glob syntax:
$ touch {ab,xyz}1234.{jpg,gif,txt,doc}
$ shopt -s extglob
$ echo @(ab|xyz)!(*@(.jpg|.gif))
ab1234.doc ab1234.txt xyz1234.doc xyz1234.txt
The exclamation point is for negation, and the @
symbol is for or.
References:
Using grep:
ls | grep -E '^ab|^xyz' | grep -E -v '\.jpg$|\.gif$'
-v
is to inverse the match
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With