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

Recommended Answers

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

Jump to Post

All 4 Replies

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

Member Avatar

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 '{}' \;
rm -f !(filename.ext)
or
rm !(*.tex|*.pdf) deletes all except the tex and pdf files

are just 2 examples.

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

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