Linux batch file discovery and deletion with find command

Hi everyone, I am trying to delete all thumbs.db files in a Windows partition using the find command in ubuntu:

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

But this does not work for me, and nothing happens! I did this trick to delete my junk files prior to the previous version of Ubuntu, but now on the latest version of Ubuntu I cannot. Is there a mistake in my team?

+8
command-line linux shell ubuntu
source share
5 answers

I would do it like this:

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

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

+36
source share

just throw it over there

 find . -name "*.pyc" -delete 
+28
source share

I am not sure why you are using while .

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

... should be enough (and delete only the files you want, and not any BDB files that can be placed).

+6
source share

The code looks good and works on arch and debian. Perhaps there are no files matching "* .db"?

As a side element: you may not be able to delete all files with the suffix ".db", because you may accidentally delete files other than "Thumbs.db"

+1
source share

First check if the first part of your command is:

to find. -iname "* .db"

returns something.

If so, you can use xargs as follows to accomplish your task:

to find. -iname "* .db" | xargs rm -rfv

UPDATE. From the comments, this is not safe, especially if there are spaces in the directory / file names. You will need to use -print0 / -print0 xargs -0 to make it safe.

0
source share

All Articles