CoolComputing Logo
Coupons/Deals  ·  New Promo Codes/Coupons  · November 13, 2018

Delete all files except

Posted on Sunday, May 27, 2001 @ 08:27:44 PM CDT by David Yee [] [read 2834 times]

Tips: Linux/Unix world
In Unix, to delete all the files in a directory except the ones that start with the letter "a", do the following:

rm [!a]*

But let's say there are many files, and you want to delete everything except a file called "my_file". Use grep's inverse matching capability here:

rm $(ls * | grep -v my_file)

Of course if there are other files with "my_file" as part of their filename, then those won't be deleted either. The following will ensure that this doesn't happen:

rm $(ls * | grep -v '^my_file$')

Please rate this article or post a brief review of Delete all files except or comment on benchmark/performance, features, availability, price or anything else regarding Delete all files except. Thanks!

Delete All Files Except Rating: 1.7/5 (11 votes cast)

Your Name:
I have read and agreed to the Review Posting Agreement.
Review Title: