Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

up vote 3 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.

share|improve this answer
add comment

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

share|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
add comment

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