-1

I want to delete different several files with the linux shell.

find . -name ".zip" | xargs rm 

The command works fine, but now I came across files which have names like this: "Revenue Backup2018.zip"

The command seems to split up the files into two files and can not find them

rm: cannot remove './Revenue': No such file or directory
rm: cannot remove 'backup2018.zip': No such file or directory

Is there a way to ignore the whitespaces?

Thank you :-)

Data Mastery
  • 1,555
  • 4
  • 18
  • 60
  • 1
    Possible duplicate of [find and remove files with space using find command on Linux](https://stackoverflow.com/questions/6242026/find-and-remove-files-with-space-using-find-command-on-linux), [Make xargs handle filenames that contain spaces](https://stackoverflow.com/q/16758525/608639), etc. – jww Nov 22 '19 at 08:36

1 Answers1

2

Instead of using xargs use find's -delete instead, ie:

find . name .zip -delete

Or tell find to output with null seperators instead so that xargs is not confused by the spaces, ie:

find . name .zip -print0 | xargs -0 rm
Geoffrey
  • 10,843
  • 3
  • 33
  • 46