3 ms·
On Illumos rm -rf / does nothing. POSIX says that removing / has undefined behavior, so the obviously smart (useful, user-friendly, GOOD) thing to do is to do
by cryptonector 9y ago
On Illumos rm -rf / does nothing. POSIX says that removing / has undefined behavior, so the obviously smart (useful, user-friendly, GOOD) thing to do is to do nothing, as that fits "undefined behavior".
- lomnakkus 9y agoThat's quite funny... but ultimately futile. It doesn't say what happens if you say "DROP TABLE xyz<ENTER>WHERE...ohshit". (The <ENTER> bit is because you're used to doing that in your preferred SQL-DB editor.) One should NEVER do anything non-scripted on a production system. ALWAYS enter it into a file and then do the "run-sql-from-a-file" command. EDIT: Yes, I also realize that "rm -rf /" can theoretically happen if you have a bad variable substitution, but you MUST turn on the flags that cause your shell to error out instead of just substituting the empty string.
- cryptonector 9y agoProtecting against every damned footgun is not possible. But some footguns blow users' feet off so often (this one because shell scripting is so tricky and dangerous) that it's est to do something about it.
- lomnakkus 9y agoIndeed not, but just having the extra step of "write this into a file" (and perhaps have someone look it over) catches most of those really bad mistakes. It's really about NOT getting into the habit of "just fix it in production". That way lies madness.
- Tepix 9y agoIf you work interactively you can use tab completion which takes care of most typos. That's something you don't have in scripts.
- earenndil 9y agorm -rf /* ?
- aarongolliver 9y agoI believe the spec says arguments can be deleted in any order, so it always chooses "current directory” first, which fails, failing the whole command
- cryptonector 9y agoCorrect.
- anyfoo 9y agoNo, doesn’t work like that, meaning it should actually delete everything. The shell is expanding /* to the list of paths, not rm, and /* does not expand to / at all. Try adding “echo “ in front of the rm command line to see how it expands. (That, by the way, is often a good idea.)
- jwilk 9y agoIt's actually required by POSIX to do nothing: If either of the files dot or dot-dot are specified as the basename portion of an operand (that is, the final pathname component) or if an operand resolves to the root directory, rm shall write a diagnostic message to standard error and do nothing more with such operands. Source: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm.html http://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm...