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]
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
Hi you can try with below command:-
ls {ab*,xyz*}.* | sed '/.jpg/d;/.gif/d'
IF you store the output into a file:-
ls {ab*,xyz*}.* | sed '/.jpg/d;/.gif/d' > shortedFile.txt
How will it work? ls {ab*,xyz*}.*
command will list out all the files begin with ab
and xyz
and redirect the output to sed
command by using |
(pipe) and sed
command will remove file name ended with .jpg
and gif
.
Hope this will help your