Say I have a piped command like this one:
$ ls -t|tail -n 10
Now if I want to remove all the files produced by the above command, if the files have spaces, it won't work:
$ rm `ls -t|tail -n 10`
# assuming the first response is 'The File Name', I get:
rm: cannot remove ‘The’: No such file or directory
rm: cannot remove ‘File’: No such file or directory
rm: cannot remove ‘Name’: No such file or directory
How can I quote the file names before sending it to rm?
IFS='\n' rm `ls the*`? – Absolute0 Jan 22 at 16:17find -print0. -- However the best choice depends on what you are trying to do, and your example "ls|cut -d ' ' -f 3|sort|etc..." is to vague for me to comment on that. – Hennes Jan 22 at 16:23rm: cannot remove ‘the file\nthe file2\nthe file3’: No such file or directory– Absolute0 Jan 22 at 16:26find /path/to/dir -name *.avi -delete {} \;. That looks like a solution to your goal, but not one to the question asked in the OP. – Hennes Jan 22 at 16:29