delete multiple files on linux with spaces in file names
- by raido
I have a directory on my Linux box with over 10000 files that I have to delete. Running...
sudo rm -rf /var/tmp/*
Gives the error message...
sudo: unable to execute /bin/rm: Argument list too long
The solution to this is to run
sudo find /var/tmp | xargs sudo rm
This only works for files with no spaces in the file name. However, some of the files have names with spaces in them and they are not deleted. For example, if a file is named 'A File With Spaces in the Name.dat', Running the command gives me errors like this....
rm: cannot remove `/var/tmp/A': No such file or directory
rm: cannot remove `File': No such file or directory
rm: cannot remove `With': No such file or directory
rm: cannot remove `Spaces': No such file or directory
rm: cannot remove `in': No such file or directory
rm: cannot remove `the': No such file or directory
rm: cannot remove `Name.dat': No such file or directory
How do I pass the complete file path to xargs sudo rm without breaking up the file name.