Just finished the 1000+ pager Unix Power Tools, Third Editionbook over Christmas break and found it a pretty good complete general introduction / refresher to Unix / Linux.

I originally passed the book up as it was last updated in 2002 but my interest was piqued skimming it and in the end I found that 98% of it’s contents still relevant today. It was like having lunch with a old-time unix guy – all the command line stuff just runs faster these days and he talks about screen instead of tmux, etc. Additionally, interesting history and tips were given on some unix programs (for ways of dropping out of a shell script faster since back in the day CPU cycles were rented).

Less known tidbits

Here are some quick notes I jotted down of some new things I learned:

pushd and popd is a great way of cd’ing to a far away path, and zipping yourself back where you were:

pushd # pop this directory on the "remember" stack
popd # go back to pop directory
dirs # see your pushd paths

I dabble in jailbreaking my phone occasionally and must download the latest jailbreak app off the torrents. This alerts the security professional in me as I have no idea what’s in the compiled code as anybody could have seeded it. The Jailbreak guys always provide an md5 verification hash on their site of their latest build and now I have the capability to validate them:

md5sum filename(s) > savedhash # create hash
md5sum -c savedhash # compare hash

Sometimes I need to modify the output of a program but also want to keep a copy of it’s unmodified output. Tee does that for me in one go.

echo 'hi there' | tee hi.txt | sed 's/hi/bye/'
# outputs 'by there' while saving original string to hi.txt

Cool way to fix command line typos:

cd bydirectory
-bash: cd: bydirectory: No such file or directory
# returns and executes: cd mydirectory

Can also do:

echo 'hi thereee'
# returns: hi thereee
# returns and executes: echo 'hi there'

Other short tidbits include:

sdiff <i>file1</i> <i>file2</i> # does side by side diff comparisons
split # split large files into smaller files
fmt # text formatter
man -k string # like M-x apropos in emacs

Lastly, put a -xv at the top of your shell scripts to debug them:

#! /bin/sh -xv