Possible Duplicate:
Remove all files but one with rm

In unix, to remove zip files in a directory one can simply type

rm *.zip

How can one remove everything except zip files?

link|improve this question

40% accept rate
feedback

closed as exact duplicate by Ignacio Vazquez-Abrams, Troggy Jan 17 '11 at 4:11

This question covers exactly the same ground as earlier questions on this topic; its answers may be merged with another identical question. See the FAQ for guidance on how to improve it.

2 Answers

up vote 2 down vote accepted
rm !(*.zip)

This appears to work. The ! represents "not".

extglob needs to be enabled in the shell behavior settings for this to work. It is probably already enabled... but if not, enable it with:

shopt -s extglob

And after answering this... indeed Ignacio Vazquez-Abrams you are correct. It is pretty much duplicate.

link|improve this answer
feedback

Try creating a list then removing the file from the list.

Ex.

ls $yourDir | grep -v .zip > deleteThis.list

the call

xargs rm < deleteThis.list

link|improve this answer
Why not just rm $(ls | grep -v *.zip) ? :) – John T Jan 17 '11 at 4:02
There's that too! :) – Dan M. Jan 17 '11 at 16:28
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.