(Yes, there are other safe ways of using
xargs, but if you care about them, read them up elsewhere. If you don't care to memorize a lot of options and scenarios, just don't use
xargs, there's usually a better way anyway.)
The problem with
xargs is that its input must be quoted in a peculiar way that no other tool produces. In particular, it can't cope with spaces in file names. You don't say what the error are (for future reference, copy-paste error messages), but chances are that one of the matching file names contains a space, and xargs choked on it.
xargs -0 copes with any strange character you may have in a file name. Pass
find to make it print the names in the right format:
find . -name "*.csv" -print 0 | xargs -0 rm
sudo find … only runs the
find command as root, not the
rm command. If you want to run
rm as root, use
find . -name "*.csv" -print0 | sudo xargs -0 rm
Under Ubuntu (and also under OSX), you can use
-delete option to delete matching files.
find . -name "*.csv" -delete
If you know that the files you want to delete are empty, better make the
find command only look for empty files, so that you don't accidentally delete other files.
find . -name "*.csv" -type f -empty -delete