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

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

find . -name "[!test.a]*.a" -not -exec rm -rf '{}' \;
rm -f !(filename.ext)
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 {} \;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.