Re:Things you (probably) didn't know about xargs
by botker on Sunday June 26, 2011 @01:00PM
(#2698410)
Never pipe `find` to `xargs rm -f`. All you need is a malicious empty file called / and you're screwed. That's why `find` has a -delete flag.
[ Parent
| on HN ]
Re:Things you (probably) didn't know about xargs
by tszming on Sunday June 26, 2011 @01:11PM
(#2698440)
A forward slash is not a valid file name.
Re:Things you (probably) didn't know about xargs
by Jach on Sunday June 26, 2011 @01:14PM
(#2698451)
The chances of such a file coming into existence accidentally and also being picked up in the find filter seem slim. If it's around maliciously, I think you have bigger problems. Anyway, there are many other failure modes of rm -rf that are a lot more likely and you should worry about.
The chances of such a file coming into existence accidentally
When sharing servers with less UNIX savvy developers you will observe A) a notoriously polluted home-directory and B) plenty of files with funny names such as -, * , [email protected] (from failed scp attempts) all over the place.
It's indeed relatively hard to create a file called '/' by accident. But I've seen files containing the '/' along with spaces, which can be just as deadly. Oh and the popular * -file is not to be taken lightly either.
As a rule of thumb: Learn the safe way to chain these commands (find/xargs in particular) once and stick to it. And always perform a dry-run before launching the real deal.
Re:Things you (probably) didn't know about xargs
by koenigdavidmj on Sunday June 26, 2011 @02:27PM
(#2698662)
Unix filenames can not include / characters or null bytes, so I call shenanigans. Nonetheless your point stands: be careful. (And make liberal use of -print0 !)
Seems you are right! I could've sworn I've seen them before, guess my memory got mixed up there.