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

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

Member Avatar for b1izzard

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 {} \;
Be a part of the DaniWeb community

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