Remove all files except for a few, from a folder in Unix

Posted by nikhil on Super User See other posts from Super User or by nikhil
Published on 2011-01-11T10:23:24Z Indexed on 2011/01/11 11:55 UTC
Read the original article Hit count: 175

Filed under:
|

I often face this problem. I have a set of files in a folder and would like to delete all of them except a few.

For example: I have files named according to the date of creation (like 11-1-11.tar, 10-1-11.tar and so on). Now I would like to delete files like 10-1-11, 9-1-11 and so on but not some other files. Basically I would like to enforce what all should be deleted and what should be retained. How would I do this?

© Super User or respective owner

Related posts about unix

Related posts about rm