Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 343
  • Last Modified:

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!
0
jkrech17
Asked:
jkrech17
  • 3
  • 3
  • 2
  • +4
1 Solution
 
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
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now