Deleting ALL files of a certain name

Hello.

From a command line (logged in as root) I want to DELETE all files on my box called "bad_file.jsp"

I did "find / | grep bad_file.jsp" and found over 70 of these, each in a different directory.  I don't want to keep ANY of them.

How can I do this WITHOUT manually deleting all 70 ?

Thanks!
LVL 16
hankknightAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brettmjohnsonCommented:
find / -name bad_file.jsp -delete

Heem14Commented:
find . -name "bad_file.jsp" -print | xargs rm

start in / directory or the directory you wish to have the process "start" in.
Gabriel OrozcoSolution ArchitectCommented:
actually, for a well defined name, starting from / is not a problem. byut the sintax is:


find / -name "bad_file.jsp" -exec rm {} \;
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Heem14Commented:
exec rm will spawn a thread for every file - not a good thing if there are hundreds or more files.

Gabriel OrozcoSolution ArchitectCommented:
good point.

but when these hundreds or thousands of files are in the same directory, the pipe redirection cannot hold that many files and fails (been there, done that) so it falls back to the good 'ol -exec rm {} \;  that can work a bit more slowly, yes, but surely will do the work.
Heem14Commented:
point being, there's many ways to skin this cat.
Gabriel OrozcoSolution ArchitectCommented:
yep!
pjedmondCommented:
I want to have a go too!:

My approach might be:

find / | grep bad_file.jsp

carries out your search. This is then pipes into gawk or awk, which takes th name and turns it into a command.

I like this approach because I can run the above, and check that what is printed out is the commands that I want the system to run. Once I'm happy, then I run the above, but pipe it though a shell:

find / | grep bad_file.jsp | gawk '{print "rm -Rf " $0}' | /bin/sh

This then executes the commands.

Although the above is longer as a command, it means that you can check exactly what commands are going to be carried out...and the awk element gives you infinite flexibility if you wanted to say change the owner of files in a certain folder to the name of the file...or any other wierd and wonderful transalation that you might consider.

Hope that helps:)


...perhaps a competition now for the most unreadable solution...or perhaps the one with least chars?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.