find and remove files with space using find command on Linux

前端 未结 5 1157
温柔的废话
温柔的废话 2020-12-14 13:38

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

find . -iname \"*.db\"|while rea         


        
相关标签:
5条回答
  • 2020-12-14 13:48

    I'm not sure why you're using while.

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

    ...should suffice (and only delete the files you want to, not any BDB files that may be laying around).

    0 讨论(0)
  • 2020-12-14 13:50

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

    As a sidenote: I might not be a good idea to delete all files with the suffix ".db", because you can accidently delete other files than "Thumbs.db"

    0 讨论(0)
  • 2020-12-14 13:50

    First check if the first part of your command, that is:

    find . -iname "*.db"

    is returning anything.

    If it does then you can use xargs as follows to accomplish your task:

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

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

    0 讨论(0)
  • 2020-12-14 13:55

    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.

    0 讨论(0)
  • 2020-12-14 14:01

    just to throw this out there

    find . -name "*.pyc" -delete
    
    0 讨论(0)
提交回复
热议问题