delete multiple files on linux with spaces in file names
Posted
by
raido
on Super User
See other posts from Super User
or by raido
Published on 2012-06-20T18:30:41Z
Indexed on
2012/06/20
21:18 UTC
Read the original article
Hit count: 197
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.
© Super User or respective owner