Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Suicide Linux (qntm.org)
272 points by brie22 on Oct 26, 2017 | hide | past | favorite | 131 comments


I've added a counter (of successful commands in a row) to my bashrc. I've seen it as high as 120.

  function promptCommand()
  {
    LAST_STATUS=$?
    # Set title of window to dir, then add new line to prompt.
    PS1='\[\e]0;\w\a\]\n'
    if [ $LAST_STATUS -eq 0 ]; then
      ((successes++))
      PS1+='\[\033[1;32m\][$successes]'
    else
      successes=0
      PS1+='\[\033[1;31m\][0 $LAST_STATUS]'
    fi  
    PS1+='\[\033[0;32m\] '
    PS1+='\w $(date +%H:%M) \$ \[\033[0m\]'
  }

  lastStatus=0
  successes=-1
  PROMPT_COMMAND="promptCommand"
My prompt:

  [0] /home/bar/g3 14:19 $ echo "boo"
  boo

  [1] /home/bar/g3 14:19 $


Man, I hope you don't use grep very often (by default it uses exit code 1 when it doesn't find anything).


If it didn't exist in the first place, then you had no business searching for it. You should have just known not to look. :)


I like this joke, it kind of reminds me of the difference between `find_by_id` and `find` in ruby on rails.

In the former, if a result can't be found it will return `nil` but in the latter it expects the record to exist and so will raise an exception if it can't be found.


Python: `Dict.get(k)` (`null`) vs `Dict[k]` (`IndexError`)


that sounds so backwards. `find_by_id` is a lookup, not a search; it seems implied to me that the ID should exist and if it doesn't that's an exception. Whereas `find` is a search and it's not atypical for search results to be empty.


Since I think rails 4 or earlier it's preferred to use `find_by(id: 4)`, but could instead be `find_by(email: "email@example.com")`, or even `find_by(first_name: "Franky', last_name: "Tomato")`.

IMO returning nil instead of an exception for the above is practical for me. Much easier to work with.

Having `find(4)` raising an exception is because you'll typical use it in your member actions for a controller where it's reasonable to want an exception if something can't be found.

It's just Rails being Rails (practical sometimes at the expense of possible interpretation of correctness). You do have to retain stuff like this in your head, but it becomes habit pretty quickly.


This begs the question of what the hell is the point of the bang convention e.g. find! in this case.


I've never seen `find!`. If that's a thing, then I have no idea why.

I've have found `find_by!` useful though. Say you want to raise an exception with `find_by!(email: "asd@asd.com")` or `find_by!(slug: "parameterized-string")` etc.


I've heard that joke once, but in C++


Negative result is still a result. I sometimes use `grep -r` to check whether "does this set of files contain this particular string?" and "no" is a useful answer :)


twas a joke.


Just pipe the output through cat. By default, the "pipefail" option is not set, so

    echo foo | grep bar | cat
is successful. Of course, this works for any command.


Alternatively and less wastefully:

    echo foo | grep bar || true


Alternatively and shorter:

    echo foo | grep bar || :


>grep

Not to mention tar which is just impossible to get right on the first try.


Especially when disarming a nuke


Nuke-practice is why I only use tar these days.


>cheat tar


This reminds me about https://www.xkcd.com/1168/


just add a '|| true' at the end of every call to grep!


just add a '|| true' at the end of every call!


If you're looking for just mistypes, use status 128.


This reminds me of Vigil, "the eternal morally vigilant programming language" https://github.com/munificent/vigil


Shouldn't the programmer also be punished? I find flagellation by static type errors unsatisfying.


First I've heard of this. Finally a keyword to beseech my needs!


What a great read. Thank you.


Deus vult!


> The reaction from the OS is actually rather underwhelming.

Somehow related, a coworker at a previous place unmounted some disks on an old AIX production box. It took him a solid minute to realise he had mistakenly unmounted / due to a typo (yes it was possible) as old processes with already opened files were happily serving stuff and only new attempts at opening files were beginning to produce errors.

Also, a similar interactive mishap in the heat of the action:

    somebox:~$ rm * .o
    rm: .o: No such file or directory
    somebox:~$ # ...
    somebox:~$ # *stares a prompt*
    somebox:~$ # Wait, what? _Please_ tell me those C files were versioned! (The answer was, obviously, "no")


Reminds me of this hilarious GitHub issue: https://github.com/MrMEEE/bumblebee-Old-and-abbandoned/issue...

(Hilarious and unnerving)


Within the first year or so of having installed Linux (mid-90's), I made the mistake of accidentally deleting /etc (wrote a script to tidy /tmp at boot, but it hadn't cd'd correctly).

That was possibly the best unix/linux learning experience of my life. Rebuilding /etc sufficient to rescue my files I cared about before a reinstall. Rescue CDs weren't really a thing, USB was a new thing at the time, and I was on dial-up.



A few months back I was wiping some old drives using a USB->SATA adapter plugged into an old Linux machine I keep around for experimenting on random things. Mostly because I could just leave it to run for however long it took. There were two drives in the machine, sda and sdb. So the drive came up as sdc.

So then I typed:

$ shred -n1 -v /dev/sda

Took me about 4 seconds to realize what I did before hitting Ctrl-C.

Then, I sighed. Considered whether I could save anything. Realized there wasn't anything on there worth saving, and reinstalled. :)

I'm usually much more cautious than that and I'm thankful it happened on a dumb test machine at home and not something important, but it was still a bummer and my first real sysadmin-type screw up. Mistakes happen, though. Even Linus once dialed his hard drive [0].

[0] https://liw.fi/linux-anecdotes/


Stuff like this is why I usually double check and only access disk by anything but the /dev/sdx or /dev/hdx labels; too easy to blow up in your face.


Shortly after I started using Fedora as my daily driver I was attempting to dd if=/dev/zero the MBR and partition table off a USB disk sdb and accidentally wiped the one off of sda instead.

As luck would have it, I had the output of fdisk -l /dev/sda in my terminal scrollback buffer and was able to recreate the partition table with no damage done.


A friend and I were working on a codebase and he did a similar typo:

rm *>o <-- kept shift held down while he pressed period

Been using "make clean" ever since.


git clean -fixd


Waay back in the day I was using crusty old shared Sun3 workstations. The keyboard was really sticky because, well, some students are pigs. I developed the habit of SLAMMING the Enter key on each command, until one day I was deleting backup files (rm *~) and my fingers grazed the delete button before striking Enter...


> The keyboard was really sticky because, well, some students are pigs.

I work at a technological youth centre, teaching kids cool things to do with computers, programming, music and whatnot. All the hardware we get is donated from businesses, schools, etc. (because volunteers / zero-budget).

And this is just ... ahh. I usually cope by trying not to notice and focus on the screen instead. Sometimes though the ick overwhelms and I fail, curse and go on a hunt for a slightly less gross keyboard. And wash my hands after--though I kind of wonder if that even really makes a difference in this particular scenario (except for the idea of it), afaik the main benefit of washing your hands (in these situations, not if you're a surgeon or a cook etc) is some kind of herd-immunity deal isn't it? And given the keyboards stay dirty, and the kids continue to work on them hands-to-keyboard-to-nose-to-mouse-to-mouth-to-keyboard-to-everything-repeat (esp. the younger ones).

You know what would be really nice? Dishwasher-safe keyboards.

And yeah (before anyone replies with a link), I'm sure those exist already. Except that many of the places that need them don't budget for new (or specialty) keyboards but rely on donated used ones. But it would be really nice to have :) :)


The solution implemented roughly a year into my position was to liberally spread cans of wet-cleaning-wipes. It was such as obvious solution and it helped tremendously.

Alternative keyboards weren't an option in those Sun 3 days, but I've brought my own chair, keyboard, and mouse to work for decades now.


Years ago, I forget how, I managed to wipe the partition table of a DOS PC. I ended up reconstructing it by hand using MS-DOS Debug and a copy of Peter Norton's book.

Another fun one: "killall" on Linux kills processes with names matching a string. "killall" on Solaris reboots the machine ...


Great choice of name for a different thing. https://xkcd.com/144/



Nope, real life occurrence. A variant includes mashing Enter on a valid rm line but on AZERTY keyboards that may mean fat fingering the nearby asterisk key.


Once I wiped /etc/passwd on a Solaris system due to a typo.

Luckily I was able to recover its contents, while hoping not to lose the network connection during the process.


The 1st line is a bit of a DOS-habit anyway, rm *o would work just as well....


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".


That'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.


Protecting 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.


Indeed 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.


If you work interactively you can use tab completion which takes care of most typos. That's something you don't have in scripts.


It'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...


rm -rf /* ?


I believe the spec says arguments can be deleted in any order, so it always chooses "current directory” first, which fails, failing the whole command


No, 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.)


Correct.


Reminds me of bash roulette. http://www.bash.org/?96164



That also reminds me of something similar, where a random offset in /dev/mem is clobbered. What potentially makes it more amusing is that it would probably just crash your machine, rather than completely destroy it.


> You know how sometimes if you mistype a filename in Bash, it corrects your spelling and runs the command anyway?

What? No, what's that about?


> What? No, what's that about?

From TFA:

"Update 2015-04-18 -- I suppose I should finally clear this up: The autocorrect functionality I originally described here was a feature of the first Linux systems I ever used, so I assumed it was how every Linux system worked by default. Since then I've come to understand that it's a completely optional extra doodad."


There's the cdspell shopt: "If set, minor errors in the spelling of a directory component in a cd command will be corrected. The errors checked for are transposed characters, a missing character, and a character too many. If a correction is found, the corrected path is printed, and the command proceeds." (https://www.gnu.org/software/bash/manual/html_node/The-Shopt...)


It's an interesting idea, but is made mostly irrelevant by tab completion.


I knew a guy who aliased all permutations of 'make' (maek, mkae, amke...) to 'make', so he just hammer the keys at once and be sure the thing would run.


I've had to do this with grep, gerp gpre gper. I've determined that I'm just constitutionally incapable of typing that word more than 2 in 3 times, and I've learned to cope with my disability.


That's for `cd smoedir` I am not aware of what would do `./smoeexec`


zsh can do that, but will prompt you before actually running anything.


Which is not really relevant because the thread and the linked article are about bash.


Yeah, I'm not aware of any distro that has this setting enabled by default. It's neat that it exists, though.


Distros in the late 90s were a lot more adventurous in their defaults as I recall.


Just have to mention, since I recognize the domain, that Sam Hughes has some excellent science fiction freely available in a serialized form here as well. Well worth investigating.


Don't miss his work at SCP wiki, either. http://www.scp-wiki.net/qntm-s-author-page


Visiting that page on mobile asked for permission to record audio and take photos...


I didn't get any such request in chrome on android. Then again, that's the kind of site with the kind of subject matter to randomly request access every nth page just for the reaction it evokes.


That's probably just a bad ad. That has never happened to me there. Sorry, though.


This is funny. I think I’ll stick with “thefuck” [1] though.

It would make a good prank to set up on someone that left their machine unlocked. Not sure if it’s more funny than changing their background to goatse.

[1] https://github.com/nvbn/thefuck


In all seriousness, what if it's a machine that no one should ever really be running commands on? This could be an effective, albeit naive, way to discourage undesirables in the system.


That is the most absurd approach to access control I have ever heard... but I like it.


Sadly, the machines I don't want people running commands on happen to be also the machines I don't want to rm -rf everything on as well.


Computers already demand a level of precision that is hard for biological lifeforms to conform to. Now this. Not sure if I should laugh or cry.


Perhaps a better name would be Roguelike Linux.


a less destructive version of this is to install `sl` on your linux or mac.


Fun story:

I was in a sys admin class with a friend of mine and we both had access to the same machine to work on our assignments. I aliased each and every common command to `sl -f` on my friend's user as a prank (he never actually logged in as it turns out). However, my instructor, while projecting his screen to 150+ students (and recording) picked our box and my friend's user to use as an example. My instructor was flabbergasted for a few minutes and the class got a kick out of flying trains. :D


That gets installed right after cowsay.

I have my priorities.




Tip: If you ever trigger sl by mistake, and you're in a hurry, press Ctrl+Z instead of Ctrl+C (which doesn't work).


That seems like a bug in sl: it should signal(SIGTSTP, SIG_IGN) (or put the terminal in raw mode, better yet)



I never type sl, but often type "gerp". I have an alias though.


My personal nemesis is "mroe". Also aliased. My wife, who drafts a lot of legal contracts, has a problem with "doe snot", which the spelling checker is more than happy with.


A friend of mine aliased `git status` `git statsu`; I, being lazier, chose `git st`. Any time saved I lost by not copying his other alias, `c = commit -amSTUFF`...


For your ~/.gitconfig:

    [alias]
	co = checkout
	psuh = push
	s = status
	l = log
	d = diff
And then alias g=git in your shell configuration. "g s", "g l", etc. But nowadays I just use magit.


I must be lazier. I use `gitst` for `git status`. That is 1/6 shorter and IMO not harder to remember.


    ~ $ abbr | grep git | sort
    abbr af 'git kit autofixup'
    abbr amend 'git commit --amend'
    abbr fixup 'git commit --fixup'
    abbr gb 'git branch'
    abbr gcan 'git commit --amend --no-edit'
    abbr gcm 'git commit -m'
    abbr gco 'git checkout'
    abbr gcop 'git checkout -p'
    abbr gfa 'git fetch --all -p'
    abbr gkdm 'git kit del_merged'
    abbr gl 'git log --oneline --color --decorate -n20 --graph'
    abbr gp 'git pull --ff-only --all -p'
    abbr gph 'git push -u origin HEAD'
    abbr gre 'git rebase'
    abbr grec 'git rebase --continue'
    abbr grem 'git rebase -i master'
    abbr greom 'git rebase -i origin/master'
    abbr greum 'git rebase -i upstream/master'
    abbr gs 'git status'
    abbr gxa 'gitx --all'
    abbr namend 'git commit --amend --no-edit'


See also SCM Breeze [0], which shortens git commands even more:

    git status -> gs
    git add -> ga
    git commit -> gc
    ...
[0]: https://github.com/scmbreeze/scm_breeze


I win:

        alias add='git add'
	alias st='git status'
	alias ci='git commit'
	alias br='git branch'
	alias di='git diff'


You all are doing way too much typing

gt git status ga git add gdd git diff to develop gdn same but name in only


`gits`

also

`gitv` = git diff

`gitvc` = git diff --cached


for me it's "date" and "data" since I type both of those quite a lot (I don't have a clock on my desktop, I just use date when I need to know the time, I find a clock distracting because I get that "well it's 27 minutes til that meeting, never getting in the the zone in that time, better check HN" thing).


I frequently try to "isntall" things...


For some reason I always type FORM in SQL and FROM in HTML. Then I edit.


installed and checked the man page, hmm 'flies like the galaxy express 999' wonder what that is

$ ls -F

dammit!

$ sl -F

So I guess it's corrected my typos already :)


reminds me my once time rather enjoyable error of "ls -l | moire" (with xscreensaver installed)


It would be nice for someone to develop a suicide-g++. Whenever you compile a program that results in Undefined Behavior, the execution of it will wipe your disk.


So it just always writes a program that does `system(rm -rf /)`?


A good read about recovering a system that had rm -rf * run on it:

http://www.ee.ryerson.ca:8080/~elf/hack/recovery.html


My team is considering running this in Production. Do you offer support contracts?


bash corrects your spelling?? Is this a cute way of saying "I made a typo that turned out to be a legit command" or is there some DWIM I don't know about (and thankfully don't have enabled)?


In the video, the banner the shell displays says:

  =========================================================
  WARNING: Suicide Linx installed
           (http://sourceforge.net/projects/suicide-linux/)
  =========================================================
I'm wondering if the typo is a subtle joke.


We should call it Russian Linux: just like how you would like to play a Russian Roulette.


Ah, that video! The good old days of Ubuntu! I just installed 17.10. :-(

Edit: The video in question: https://www.youtube.com/watch?v=Q_pgnMWgd34


One idea I like is randomly flipping a bit on the root partition every day or so. You'll have to take an incredibly long time to find the problem, of which there will be one eventually.


Some like to learn by the stick, while others by carrot. And some like to learn with a grenade.


Haha, how can it do that out of interest, if you're not root? (As aren't the top level directories in / owned by root?, or does it work anyway, if rm can recurse down? deleting files from the current user)


In the video he says that you need to be root when you make the typo. But since you have to be root when you install the package, you could plant a suid binary or even leave a service running as root that deletes all your files later.


As far as I know, it can recurse down and get to more files than you want. The alternative is that the last time I ran that command, it was actually on an account with write rights to the root dir.


A bit too unforgiving for my taste :) To err is .. destruction!


Shouldn't this be more accurately called Seppuku Linux?


He seems to have forgotten the --no-preserve-root flag.


This was made before they added that flag :)


not enough, I want a 5 seconds timer on every new attempted input line. You either type something or you don't.


THis is not nearly as hard corre as it would have been in the days before Xen.


Good to have snapshots (zfs) that you can go back to after a screw-up.


Just pray that the snapshot restoring program wasn't gone.


Is this the digital equivalent of corporal punishment?


Is this a package or a true operating system distro?


I just wasted 2 minutes of my life reading this.


Docker image? It completely defeats the thrill.


1) death by accident (or rm -rf'ing) is not suicide 2) has the bar been lowered that much now? a simple bash configuration makes a new O/S or distribution?

:-)


What a fun OS!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: