0

Hi,
i'm using the following cmd to remove all lib files ending with .a

find . -name "*.a" -exec rm -rf {} \;

I have a file which i dont want to delete , say test.a,
I just want to know how to make rm not delete test.a,
but delete rest all files ending with .a

Edited by srinivas88

5
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by ramaakella
1

see -not swich for find and take out r from rm to remove one by one. That would leave directories there, however.

Edited by pyTony

2

Just give the name of the file you don't need to delete in the regular expression
like

find . -name "[!test.a]*.a" -not -exec rm -rf '{}' \;
1
rm -f !(filename.ext)
or
rm !(*.tex|*.pdf) deletes all except the tex and pdf files

are just 2 examples.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.