10
7
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.
Simple wildcarding may be your solution: rm file* will remove file1 and file2 but not dontdelete. If your needs are more complex then, depending shell scripting language, you could generate a list of files you want to delete using a regular expression and pipe this to the rm command. – therobyouknow – 2011-01-01T04:57:26.187
@Rob: Yeah, my situation is more complex than that. And Ignacio's answer worked. Thanks, though! – Wuffers – 2011-01-01T04:59:56.143