Search code examples
linuxbashrm

Remove all files contain specific string - Bash


I have these bad data

AWS-Console.pngcrop-AWS-Console.png                                                                                    
Alimofire.pngcrop-Alimofire.png                                                                                        
Amazon-ECR-.pngcrop-Amazon-ECR-.png                                                                                    
Amazon-ECS.pngcrop-Amazon-ECS.png                                                                                      
Amazon-RDS.pngcrop-Amazon-RDS.png                                                                                      
Angular.pngcrop-Angular.png                                                                                            
AngularJS.pngcrop-AngularJS.png 
.... 1000 more

I'm trying to delete them

I've tried

ls public/assets/fe/img/skill/ | grep crop | rm -rf *crop*
ls public/assets/fe/img/skill/ | grep crop | rm -rf
rm -rf $(ls public/assets/fe/img/skill/ | grep crop)

None of them work ...


Solution

  • rm can handle the glob expressions that ls handles:

    rm public/assets/fe/img/skill/*crop*