not?

0 views
Skip to first unread message

Sidney_Kotic

unread,
Apr 16, 2022, 9:12:34 PMApr 16
to
Long, long ago back when I was using DR-DOS there was a nice command that looked
something like this:
not *.pdf del *
And everything except *.pdf went into the bit-bucket. Basically it worked by
setting the "h" attribute on the *.pdf file(s), run the command, and then
removing the "h" attribute.

Is there a bash utility like this?

Malcolm

unread,
Apr 16, 2022, 9:51:38 PMApr 16
to
find . -type f ! -iname "*.pdf" -delete

--
Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
Tumbleweed 20220414 | GNOME Shell 42.0 | 5.17.2-1-default
HP Z440 | Xeon E5-2690 V3 X24 @ 2.60GHz | AMD RX550/Nvidia Quadro T400
up 3:07, 2 users, load average: 0.83, 0.58, 0.30

Sidney_Kotic

unread,
Apr 16, 2022, 11:32:24 PMApr 16
to
On 4/16/22 17:51, Malcolm wrote:

> find . -type f ! -iname "*.pdf" -delete


alias not="find . -type f ! -iname "
not "*.pdf" -delete

Pretty close, thanks. I'll fiddle with it more in the morning, there's a beer
in the fridge calling my name LOUDLY.

marrgol

unread,
Apr 17, 2022, 2:40:42 PMApr 17
to
On 17/04/2022 at 03.12, Sidney_Kotic wrote:
> Long, long ago back when I was using DR-DOS there was a nice command that looked
> something like this:
> not *.pdf del *
> And everything except *.pdf went into the bit-bucket. […]
>
> Is there a bash utility like this?

shopt -s extglob
rm !(*.pdf)


--
mrg

Sidney_Kotic

unread,
Apr 17, 2022, 3:19:20 PMApr 17
to
Hmmm...seems like I led you astray. It's not just rm I was interested in.

What I meant was something like this:
not somecondition somecommandwithparameters

not vacation*.gif tar -cf ../vacationjpgs.tar *
or
not *.mp3 cp -v * /someplaceelse
etcetera

marrgol

unread,
Apr 17, 2022, 6:12:06 PMApr 17
to
On 17/04/2022 at 21.19, Sidney_Kotic wrote:
> Hmmm...seems like I led you astray. It's not just rm I was interested in.

> What I meant was something like this:

> not vacation*.gif tar -cf ../vacationjpgs.tar *

tar -cf ../vacationjpgs.tar !(vacation*.gif)

> not *.mp3 cp -v * /someplaceelse

cp -v !(*.mp3) /someplaceelse

> etcetera

RTFbashM


--
mrg
Reply all
Reply to author
Forward
0 new messages