In the past few years I managed to discover
some nice unix / unix-inspired utilities that
are, simply, life-savers.
Not sure if you already know all the
stuff here, but I hope you’ll be able to find
this brief list useful!
watch
Ever needed to run a command multiple times at a certain interval?
Enter watch.
(funny enough, my friend Cirpo
yesterday told me “Why do everytime I have to look for a unix command I end up on a bad-looking webpage?”)
Anyhow, at its core, watch -n X cmd simply re-executes cmd every X
seconds:
123456
~ ᐅ watch -n 1 "mysql -h 127.0.0.1 -u root -proot -e 'show processlist;'"
Every 1.0s: mysql -h 127.0.0.1 -u root -proot -e 'show processlist;' Wed Jul 15 18:30:19 2015
Id User Host db Command Time State Info
10 root 172.17.42.1:56805 NULL Query 0 init show processlist
Useful when you’re waiting for something to happen!
htop
If you are familiar, and possibly frustrated with, top you will
definitely love htop.
In general, just imagine top with a better user-interface and
an intuitive way to sort, filter and so on.
$?
Oh Jesus, help with exit codes here!
Ever ran a program to then wondered what its exit code was?
You can simply do it with a $? which will return the exit
code of the last command you executed:
123456789101112131415
/tmp/test ᐅ ls -la
total 44
drwxrwxr-x 2 odino odino 4096 Jul 15 18:40 .
drwxrwxrwt 24 root root 40960 Jul 15 18:40 ..
/tmp/test ᐅ echo $?
0
/tmp/test ᐅ ls -la non-existing
ls: cannot access non-existing: No such file or directory
/tmp/test ᐅ echo $?
2
/tmp/test ᐅ i-dont-exist
zsh: command not found: i-dont-exist
/tmp/test ᐅ echo $?
127
/tmp/test ᐅ
screen
You SSH into a server, run a command, the internet goes off…profanities all
around you!
A hidden gem I really like to use is the \G option when doing SELECTs,
which will format returned records in a very particular way (vertically-aligned, though it’s
only doable for queries that return very few results):