Remove .backup files recursively in Linux

Hi,

I ran a program against a directory and it duplicated every file adding .backup to the end.  I am trying to remove all these files recursively; however, when I try to rm -r *.backup it still is pulling files without the .backup extension.

What would be the most efficient and accurate way to recursively go through directories and remove files with .backup at the end such as test1.php.backup.  

Thanks!
jkrech17Asked:
Who is Participating?
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.

steve918Commented:
rm -r *.backup should work, you say it's deleting files w/o .backup extension?

-Steven
0
jkrech17Author Commented:
Yes, it asks me if I want to decend into the directory adn is listing files without the .backup extension to delete.
0
steve918Commented:
What OS are you using?

try rm -rv *.backup  it will show you exactly what's going on.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ramazanyichCommented:
try to put quotes around your mask:
rm -r "*.backup"
0
LuxanaCommented:
you can also use find command to remove all *.backup files from selected directory:

find /yourdirectory -name *.backup -exec rm -v {} \;
0

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
wesly_chenCommented:
Hi,

  Luxana's command should work fine. I will add one option to make sure you don't delete the directory.

# find /yourdirectory -type -f -name *.backup -exec /bin/rm -v {} \;
-type f : will list files only, no directory
/bin/rm: to avoid some alias for rm since recursively running "rm" is very dangerous.

Regards,

Wesly
0
wesly_chenCommented:
Oops, typo, it should be
# # find /yourdirectory -type f -name *.backup -exec /bin/rm -v {} \;

Wesly
0
LuxanaCommented:
>  Luxana's command should work fine. I will add one option to make sure you don't delete the directory.

wesly with rm command you can't remove directory and definitely can't if is not empty . You can do so only with -fr switch.

Also if you want make sure that what are you deleting use -i in rm command.

find /yourdirectory -type f -name *.backup -exec /bin/rm -vi {} \;
0
wesly_chenCommented:
> with rm command you can't remove directory and definitely can't if is not empty . You can do so only with -fr switch.
Yes, but some people just do
alias rm  "rm -rf"
in their .bashrc or .cshrc.
That's why I use /bin/rm to eliminate this kind of hassle.

Thanks for your comment.

Wesly
0
LuxanaCommented:
> Yes, but some people just do alias rm  "rm -rf" in their .bashrc or .cshrc.

Yes but according jkrech17 comment :
Yes, it asks me if I want to decend into the directory adn is listing files without the .backup extension to delete.
--
this is not our case.

./lubo
0
yuzhCommented:
To recursively remove *.backup files  under the current dir:

find . -type f -name "*.backup"  -exec rm {} \;

Recursively remove  *.backup from your system:
find / -type f -name "*.backup"  -exec rm {} \;


You need to quote "*.backup"

man find
to learn more details.
0
rugdogCommented:
you can also escape * with no quotes:

find . -type f -name \*.backup -exec rm {} \;
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.