What language is this?
This is a phrase in bash. Bash is the command language under the hood of macs and most web servers. Specifically, this is a suffix you'd tack on after another command.
What does it say?
">" redirects output from that command somewhere else. Adding the 2 on front only grabs part 2 of the output - the errors.
/dev/null is nowhere. It's a black hole.
So this is a phase we tack onto a mac command under the hood to ignore error messages. (Literally, to redirect error messages into the void.)
Tacking this onto the end of a command strips out the crap error messages flooding your results and leaves the success lines you were searching for. And I <3 that.
Tonight I'm searching a stranger's code to figure out why an event that I want to happen isn't happening. So I'm running a lot of commands like this:
grep -n "FROM LoginInfo" `find ./ -name "*.j*"` 2> /dev/null
grep is the "Global Regular Expression Parser". It's an all purpose search command. I'm using it to look for the text "FROM LoginInfo". The -n bit tells it that I also want to know the line number whenever it finds that text in a file.
The next part is telling it where to look. grep commands normally look like:
grep <what> <where>
In this case, I've got another command within backticks in the where slot:
`find ./ -name "*.j*"`
The backticks say, take this command, and use it's output in this spot.
I'm using the find command to list every file that has a 'j' in the last part of it's name, from this directory on down.
So, in full, the command:
grep -n "FROM LoginInfo" `find ./ -name "*.j*"` 2> /dev/null
translates to:
Find everywhere that "FROM LoginInfo" appears in any file with a j in its name from this directory on down. Tell me what line number you found it on, too, and don't bother me with all the places you couldn't find it.
Why is that awesome?
Screw the haystack. Here's the needle I'm looking for, in 0.2 seconds.