Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find and remove files with space using find command on Linux

I'm trying to remove all thumbs.db files in a Windows partition using find command in Ubuntu:

find . -iname "*.db"|while read junk;do rm -rfv $junk;done

But it's not working for me and nothing happens! I think I found the problem, the white spaces in directory names!

I did this trick to remove my junk files before on previous version of Ubuntu but now on latest version of Ubuntu I can't.

Is there any bug in my command?

like image 631
Ahmad Azimi Avatar asked Jun 05 '11 09:06

Ahmad Azimi


People also ask

How do I use find when the filename contains spaces?

Use find command with a space between two wildcards. It will match files with single or multiple spaces. "find ." will find all files in current folder and all the sub-folders. "-type f" will only look for files and not folders.


1 Answers

I'd do it this way:

find . -iname 'thumbs.db' -exec rm -rfv {} +

This way, it still works even if your directories contain whitespace in their names.

like image 197
Chris Jester-Young Avatar answered Oct 06 '22 00:10

Chris Jester-Young