Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell Scripting: Using bash with xargs

I'm trying to write a bash command that will delete all files matching a specific pattern - in this case, it's all of the old vmware log files that have built up.

I've tried this command:

find . -name vmware-*.log | xargs rm

However, when I run the command, it chokes up on all of the folders that have spaces in their names. Is there a way to format the file path so that xargs passes it to rm quoted or properly escaped?

like image 432
Dan Monego Avatar asked Oct 19 '09 18:10

Dan Monego


2 Answers

find . -name vmware-*.log | xargs -i rm -rf {}

like image 94
rh0dium Avatar answered Nov 04 '22 23:11

rh0dium


GNU find

find . -name vmware-*.log -delete
like image 27
ghostdog74 Avatar answered Nov 05 '22 01:11

ghostdog74