5 ms·
To be clear, the problem described in the video is not something that can happen. "rm -rf $1/$2" where $1 and $2 aren't defined (therefore making it "rm -rf /")
by Etzos 11y ago
To be clear, the problem described in the video is not something that can happen. "rm -rf $1/$2" where $1 and $2 aren't defined (therefore making it "rm -rf /") will not run. If you really want to destroy your root directory you have to specify the --no-preserve-root flag. No more accidents from scripts that assume things poorly, but it will still do exactly what the user asks.
- protomyth 11y agoYet, I can still delete my home directory by accident (e.g. Steam patch). The idea that any rm can kill the directory I'm in is just bad. A flag on rm is the wrong solution. It should just fail.
- ambrice 11y agoSo you're saying they should remove the -r option entirely from rm?
- protomyth 11y agoNo, I'm saying that delete the current directory I am in is bad (as in non-standard behavior) and should not be allowed. Asking if I want -r removed has nothing to do with anything.
- Etzos 11y agoI disagree with this almost completely. If I tell my computer to do something it should just do it (possibly after some complaining). You cannot delete the directory you are immediately in, so that at the very least is prevented. But as you move away from just root the usefulness of deleting nearby folders and files actually becomes useful. And putting those kinds of things is absolutely a reasonable solution. It keeps you (and scripts) from shooting yourself in the foot but lets you do things as long as you acknowledge what you are actually doing.
- protomyth 11y agoI said "The idea that any rm can kill the directory I'm in is just bad. A flag on rm is the wrong solution. It should just fail." you say "You cannot delete the directory you are immediately in, so that at the very least is prevented." I have no idea what the rest of your comment is in relation to what I said other than I'm pretty sure you can accidentally delete a directory your in given what Steam did. Deleting you current directory is against the POSIX standard. It should not be allowed.
- Etzos 11y agoWhat I was saying was that "rm -rf ." just won't work. You cannot delete the directory you are in directly ("." and ".." are not valid options). If however you delete a directory that is higher up the directory tree (e.g. the parent directory), it will be deleted. As far as I can tell this does not violate the POSIX standard[1], as that situation is left as undefined (since in theory the directory you are deleting will chain to the directory you are currently in which is open in the tty). Edit: The rest of my previous comment was trying to say that the utility of being able to self destruct the current directory is arguable. Why should it be prevented (especially when it could just be hidden behind a flag to prevent accidental destruction)? Edit2: D'oh. Forgot the reference: [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/rmdir.html http://pubs.opengroup.org/onlinepubs/9699919799/functions/rm...
- protomyth 11y ago"If the current working directory of the process is being removed, that should be an allowed error." Ok, I read that wrong a long while back, but "allowed error" is really odd. I guess I still side on an error is an error and it should not be allowed.
- sillysaurus3 11y agohttps://github.com/valvesoftware/steam-for-linux/issues/3671#issuecomment-70021818 https://github.com/valvesoftware/steam-for-linux/issues/3671... rm -rf "$STEAMROOT/"* When $STEAMROOT was empty, "steam apparently deleted everything owned by my user recursively from the root directory. Including my 3tb external drive I back everything up to that was mounted under /media."
- dTal 11y agoWow that is an annoying example. Aside from not following the Golden Rule of shell variables (always consider the unset case), why on Earth didn't they just write rm -rf "$STEAMROOT" ? The trailing slash and asterisk do nothing. Cargo-cult scripting. Ick.
- the_why_of_y 11y agoIt could happen in the past. Actually Solaris 10 was the first to fix it: http://web.archive.org/web/20061021192240/http://blogs.sun.com/jbeck/date/20041001 http://web.archive.org/web/20061021192240/http://blogs.sun.c... GNU coreutils changed the default to --preserve-root some years later, in version 6.2: http://git.savannah.gnu.org/cgit/coreutils.git/tree/ChangeLog-2006#n1570 http://git.savannah.gnu.org/cgit/coreutils.git/tree/ChangeLo...