This Slack discussion, featuring myself in some sleep-deprived rambling, occurred in hackernoon's official #protips channel, and has been [barely] edited for readability.
austin
YSK about lsof
, short for ālist open filesā. since everything, literally everything from network sockets to camera handles, is a file in unix-based systems (like macos). this means you can do things likelsof | grep "AppleCamera"
in the terminal, to see if anyoneās using your camera (even if the little light is off)
or you can do
lsof -i -P -n | grep LISTEN
to see all programs with open network ports, if you want to say, kill a webserver that ran away on you, to open up the port. or if youāre locking down a machine. the thingās a power tool
austin
or netcat
! talk about power tools. that thing will send literally anything over anything. want to test an old PPP connection? send a āmaliciousā packet to test your webserverās mettle? see what happens when you send a UDP formatted packet over TCP? netcat
. more unix tools incoming, in this thread austin
how about tcpdump
? itās basically wireshark before wireshark was cool ā if youāre on an ssh connection in particular, might be worth brushing up on tcpdump
(i know, wireshark can work over an ssh connection, but imagine youāre on a desert island. with a computer.) point is, these old school tools can be useful sometimes too (and can be piped together like any olā unix tool) austin
ok so itās decided: this is a thread about useful unix tools. please donāt post in here, people ā iām going to turn this into a post later austin
screen
is a good one too. (iām just thinking these up off the top of my head, so if i seem all over the place, itās because i am). the screen
tool will keep a program running even if your ssh connection fails! talk about useful austin
oh! strace
/ptrace
! those things are amazing. you can basically poke around inside a running program. think of it like game genie for your code austin
curl
. one of the most underrated tools on unixā¦you can test an whole ass webserver with curl
. i mean, there are a thousand tools for āREST testingā these days, but curl
is the og. austin
grep
, again underrated and used to death. especially powerful with unix pipes. i mean, you can combine grep with literally any other tool in this list, except maybe screen
and only because that wouldnāt really make senseā¦unless youāre grepping redirected output? idk. point is, all these tools can talk to each other using a standard format, one we all know: text! austin
btw, at this point, itās worth mentioning: half the cool unix tricks iāve learned, i learned from https://twitter.com/b0rk aka https://jvns.ca/, creator of http://wizardzines.com. check it! she knows more about unix and linux systems than i can probably ever hope to, and she presents it in a really fun, digestible format. austin
letās seeā¦ssh
is actually more powerful than most people realize. you can set up āchainsā of ssh connections, you can set up all sorts of crazy network configsā¦.i mean, it does more than just remote terminal logins. austin
fun fact: emacs
(and vim
too, i believe) have an interface for editing remote files on your local instance! so no more using default vi
to edit files over ssh! š austin
awk
! i forgot about awk
, because everyone does. basically, if you have data thatās spit out in a columnar format like ps
, or lsof
, or [insert any unix tool on the planet], you can use a simple awk
command to pull a single value out of a given column, and so much more. which i donāt know off the top of my head because the columnar data processing is all iāve really needed. but in a pinch, you can even use it like grep
austin
sed
ā¦here be dragons, folks. short for āstream editorā, sed is like find and replace on some super steroid derived from the blood of all the disgraced baseball players in the 90s. anyway, sed can do stuff like find and replace every single instance of a regex match with another string or pattern (including regex capture groups!), in place. meaning it will edit your files with no recovery plan, no backup. thatās why i say: here be dragons. this is a power tool so powerful, you can cut a limb off. be careful. austin
tar
is useful, but damned if i remember how to use it. thereās even https://xkcd.com/1168/. i mean you can create the unix equivalent of zip files, and decompress them as well. itās useful, i justā¦i need google to use it. austin
find
is a good one. i mean, if you ever need to find something and donāt have the luxury of macosās finder features, this is your tool. it can find files with a pattern, using modification time, and so much more. combine with a unix pipe and xargs
for extra fun! austin
xargs
, thatās useful as well. basically itās the unix equivalent of the āspread operatorā in JS, if that makes sense. austin
two more: the first, man
, is essential for any unix or linux user. itās quite simply, the manual pages. use it as a system reference, for remembering what a given flag does, or whenever $TOOLNAME --help
doesnāt cut it austin
the last is apropos
ā literally. this will, given a keyword, tell you which tools are appropriate for your use case! like if you type apropos file
, itāll tell you about file-related tools. itās like the index they used before search engines sort of drove it into the shadows austin
hope you enjoyed this sleep deprived rant! back to my regularly scheduled programmingā¦