Tips & How-To's

Remove all files but one with rm

Is there any way to remove all of the files in a directory except for one with a certain filename? For instance, if I had a directory containing the files file1, file2, and dontdelete. Would there be any way to quickly delete file1, and file2 and not dontdelete? I know that I could just do rm file1 file2 but that wouldn’t work for a bunch of files. Also, I’m on Mac OS X if that makes a difference

via command line – Remove all files but one with rm – Super User.

Nice tip.

One Comment

  1. Pingback: Sathya

Leave a Reply

Your email address will not be published. Required fields are marked *