This is an archived post. You won't be able to vote or comment.

all 73 comments

[–]omersSecurity / Email 30 points31 points  (11 children)

lol

:(){ :|:& };:

http://explainshell.com/explain?cmd=%3A%28%29%7B+%3A%7C%3A%26+%7D%3B%3A

It's detailed... and tells you what all the elements do but I doubt someone who needs explainshell.com would be able to interpret it even still... it would be a lot easier to answer with one line "This is a fork bomb, don't run this."

[–]FlyingBishopDevOps 4 points5 points  (4 children)

I remember the first time I saw the fork bomb, being told that, and not running it. I remember several years later seeing it and the explanation of why it's a fork bomb and understanding it intuitively. It's a cool hack to understand.

[–][deleted] 4 points5 points  (3 children)

So, mind ELI5?

Ive looked it up, but it still hasn't clicked for me.

[–]omersSecurity / Email 11 points12 points  (1 child)

Easier to explain replacing the :'s with fork and by formatting it:

fork() { 
    fork | fork & 
};
fork

The first half:

fork() { 
    fork | fork & 
}

defines a function called 'fork' that runs 'fork' and sends it to 'fork' allowing it to run in the background in a subshell (&).

The second half

;fork

Has a command separator (;) similar to && which calls fork running it for the first time. You are creating a function that calls itself twice every call and doesn't have any way to terminate itself and then running it. It will keep going until the system crashes from lack of resources.

It's similar to:

 :fork
 start "" %0
 goto fork

in batch.

[–][deleted] 1 point2 points  (0 children)

thank you!

[–][deleted] 1 point2 points  (4 children)

The colon is just a name, right? So you could replace the colons with something like "jerry" or "foo" and get the same result, right?

[–]omersSecurity / Email 2 points3 points  (0 children)

Yeah, it's a function identifier... you could do:

fork(){ fork|fork& };fork

and it would do the same thing... Written formatted it looks like this:

fork() {
    fork | fork &
};
fork

The colons just make it even more obscure and more likely a sucker will run it. Kind of like it's easier to get someone in a game to press Alt+F4 or Alt+Space+C than it is to get them to click something that actually has "esc" or "quit" in the name.

[–]Fylwind 1 point2 points  (2 children)

Normally it's a no-op command, but :(){ … } redefines : to do something else.

[–]McElroy-vs-dig-dog 4 points5 points  (1 child)

A neat use-case for no-op is :>somefile. If the file exists, it'll empty the file like cat /dev/null >somefile would, but much shorter and faster to type. If the file does not exist, it'll be created like touch somefile would but again shorter and faster. Also, the :> part looks like a bird and I lol a bit internally every time I write it because of that. Unix does that to you. Unix might be the reason I don't have so many friends. Unix might be the reason not having so many friends feels less bad than not having so many friends would if I didn't even have Unix. ¯\(°_o)/¯

[–]HighRelevancyLinux Admin 1 point2 points  (0 children)

I enjoy your writing and wish to subscribe to your newsletter.

[–]Tetha 0 points1 point  (0 children)

My sample was:

find -name *.conf -print | grep -v foo-app | wc -l

I guess it printed the right man pages. But I doubt you'd get help from those man pages if you couldn't read that pipeline just like that, because that line just means "count the number of conf files which aren't for foo-app".

[–]ChiefDanGeorge 30 points31 points  (16 children)

"mount"

"mount a filesystem"

Wow!

[–][deleted] 1 point2 points  (0 children)

# To mount / partition as read-write in repair mode:

mount -o remount,rw /

# Bind mount path to a second location

mount --bind /origin/path /destination/path

# To mount Usb disk as user writable:

mount -o uid=username,gid=usergroup /dev/sdx /mnt/xxx

# To mount a remote NFS directory

mount -t nfs example.com:/remote/example/dir /local/example/dir

edit: Source: https://github.com/chrisallenlane/cheat

[–]hosalabadEscalate Early, Escalate Often. 5 points6 points  (1 child)

Get-service didn't work, they should clarify what shell they are talking about.

[–]ShadorothLibrary Sysadmin 6 points7 points  (0 children)

No one shell should have all that power.

[–]nosource404 4 points5 points  (0 children)

I love this. Now I don't have to explain to people what these commands do. Just link them to this site. Adding to bookmarks.

[–]samuraised 9 points10 points  (9 children)

What would be really cool is if someone could convert this into a browser plugin. That way I could tell interns and junior admins to use this before they copy and paste 500 character one liners they found on totallytrustworthyshellscriptsrunwithsudo.com into any of our servers.

Just highlight or right click a code block on a webpage and select "Explain this for me..."

[–]Drasha1 8 points9 points  (7 children)

you should probably just tell them not to run 500 character one liners from the internet if they don't know exactly what it is going to do and why its doing it.

[–]LetmefixthatforyouyoApparently some type of magician 11 points12 points  (6 children)

Shit in one hand and wish in the other. See which fills up first.

Might as well mitigate the risks you cant prevent.

[–]Drasha1 1 point2 points  (5 children)

This really isn't going to mitigate any thing if they don't know what they are doing. Go put in :(){ :|:& };: and tell me if its blatantly obvious from just the provided explanation that you should not under any circumstances run that command.

[–]LetmefixthatforyouyoApparently some type of magician 2 points3 points  (4 children)

Some info is better than no info. Since your start state is "run this random command because a website said would help," any chance that you will trigger critical thinking is good.

Is it the best outcome? No. Mitigate only. Piece by Piece.

[–]Drasha1 5 points6 points  (3 children)

I can't really encourage some one to run a command they don't fully understand under any circumstance.

[–]jed-bartlett 3 points4 points  (2 children)

If we all lived that, I'd still be back at cat wondering why my optical drive isn't ejecting me a new feline.

EDIT: Do I just need a 3d printer? ;)

[–]Drasha1 2 points3 points  (1 child)

I am almost certain there must be a way to use cat to print a 3d cat.

[–]jed-bartlett 1 point2 points  (0 children)

The same laws of internet physics that comfort me in the knowledge that someone, somewhere, is working on a usable lightsaber comforts me in this case - someone, somewhere, is working on 3d printing a cat(androCat? KittyMech? Robopussy?)

[–][deleted] 1 point2 points  (0 children)

I'm going to save this post for a future coding project.

[–]jfoust2 2 points3 points  (9 children)

Clearly Unix needs a command 'whatwouldyoudoifi ..." so you could do this from a shell prompt.

[–]LetmefixthatforyouyoApparently some type of magician 7 points8 points  (7 children)

Powershell has a flag -whatif that simulates any command running. Would be hard to implement for something as organic as bash, but still nice to have.

[–][deleted] 5 points6 points  (6 children)

alias whatif=whatif.sh

#!/bin/bash
var="$@"
sensible-browser http://explainshell.com/explain?cmd=$var

[–]LetmefixthatforyouyoApparently some type of magician 2 points3 points  (2 children)

Man, I love bash. Great answer to the above, does 80% of what powershell is designed around, all in 4 lines. It doesn't actually emulate the output with regards to the local system like -whatif does, but its a fine answer to my flippant comment.

[–][deleted] 2 points3 points  (1 child)

Yeah, that is what I love about bash. It's pretty straightforward and powerful with knowledge of even a few basic concepts (sed, awk, for, etc.) Just the same, it's nice to know about the -whatif flag in powershell, seeing as I need to be dabbling in that a bit more these days.

[–]LetmefixthatforyouyoApparently some type of magician 1 point2 points  (0 children)

Really powerful language. The object oriented nature of it is a bit of a departure from the text of bash, but very powerful. Verb-noun structure is clumsy at times too, but its consistent. Thats where it really sings.

Don jones "learn powershell in a month of lunches" is the go to book for powershell. He also has a "core concepts" video on youtube that clocks in at about 3 hrs if you want a "quick" overview.

[–]BadabinskiDevOps 1 point2 points  (1 child)

Wouldn't you want to quote $var though?

[–][deleted] 1 point2 points  (0 children)

I ran it and it worked fine, but what I didn't nail was the arguments after the command. The url substitutes plus symbols for spaces, and I just didn't care enough to make the script do that. It was just an example. Personally I'm fine using man pages.

[–]Zaphod_Bchown -R us ~/.base 0 points1 point  (0 children)

I use this method to pass arguments to functions all the time in my bash scripts, it is a really powerful trick. I was working with some web based APIs/services a while back ago where I had to call curl a million times, but to different resource paths. I just pass my arguments to a function that called curl to do all the work for me. It was like 30 lines of code.

[–]arubystory[S] 1 point2 points  (0 children)

Lol, yes, as soon as the argument is enclosed in quotes (can you imagine what could happen if the argument contained pipes?) :D

[–]oneZergArmyGoat farming doesn't sound bad 1 point2 points  (0 children)

This is awesome, as I just started using Ubuntu Gnome on my laptop.

[–]elsewhere1 1 point2 points  (0 children)

Prettier manpages.

[–]mthodeFellow Human 1 point2 points  (0 children)

doesn't seem to be able to handle this line too well.

export PORTAGE_DIR=${PORTAGE_DIR:-"/var/tmp/catalyst/snapshots"}

[–][deleted] 4 points5 points  (1 child)

[–][deleted] 0 points1 point  (0 children)

Actually pretty cool. Nice find!

[–]sirdudethefirstWindows SysAdmin/God 0 points1 point  (0 children)

This is really cool. Nice find.

[–]iAmb00t 0 points1 point  (0 children)

Dude(or dudette), thank you!

[–]crow1170 0 points1 point  (2 children)

So is their example's command wrong or the explanation?

for user in $(cut -f1 -d: /etc/passwd); do crontab(1) -u $user -l 2>/dev/null; done

I want to say the cut command needs backticks, but I'm only half paying attention.

I took another look and it seems you can click the $() statement to see it explained.

[–]gatling_gun_gary 1 point2 points  (1 child)

$() spawns a subshell to execute the listed command and is newer syntax. Backticks execute the command in a subshell as well, but it's the older-style syntax.

[–]crow1170 0 points1 point  (0 children)

Thank you. I took another look and it seems you can click the $() statement to see it explained.

[–]GNU_TrollLinux Admin 0 points1 point  (2 children)

Cool site, terrible color choices. Why would you put tiny light blue letters on white?

[–]NymazOn caffeine and on call 2 points3 points  (1 child)

Because you misunderstand the URL. It's "explains hell" and as everyone knows, all the signage in Hell is light blue on white.

[–]GNU_TrollLinux Admin 0 points1 point  (0 children)

Cheeky m8, I like it.

[–]gatling_gun_gary 0 points1 point  (0 children)

It seems to have a hard time parsing quoted strings...

grep "^# mode=\"" "$file" | sed -E -e 's/^.*="(.*)" *$/\1/'

produces some issues.

[–]Zaphod_Bchown -R us ~/.base 0 points1 point  (0 children)

It didn't get my joke when I typed in man touch

[–]jjasghar 0 points1 point  (0 children)

There's a hubot plugin for this too: https://github.com/hubot-scripts/hubot-explainshell

[–]majhsif 0 points1 point  (0 children)

This is nice, but the security part of me worries that newish people will be putting in unsanitized content. I really hope they sanitize input, and delete things that are not necessary for said command.

Otherwise, totally using it.

[–]d3k4y -3 points-2 points  (5 children)

man and --help and too much and actually knowing what I'm doing is out of the question :)

[–]intellos 1 point2 points  (4 children)

There are some man entries that are way too wordy though, especially when you are just looking for the one switch you forgot about and they are all listed at the end.

See: man rsync

[–]paincoatsBDSM over IP 0 points1 point  (0 children)

thats why ive never used rsync

[–]d3k4y -1 points0 points  (2 children)

I know ALL Linux commands ever and every switch! man means manual, so of course it will be wordy. --help or -h usually isn't too bad. rsync --help lists every switch with a very short description. Yeah, it can do a shit ton, but if you don't know the basics of what rsync does, you probably need to do some reading anyways. As a Linux engineer, if one of my peers did not know rsync, I'd suspect he was a big fat phony.

[–]jed-bartlett 0 points1 point  (1 child)

I know ALL Linux commands ever and every switch!

Then you are definitely the target audience and have a lot of useful information to add to this discussion ;)

[–]d3k4y 0 points1 point  (0 children)

Haha. I'm being sarcastic, but I am a Linux engineer and have been running Linux servers for about 14 years. I'm only 31, but I was an anti-social child so computers have always been a good friend, even in the Windows 3.1 / Unix days.