Monday, November 21, 2011

Shell gems

Leave a Comment
I found a really good thread via +Patrick Aljord today called Give me that one command you wish you knew years ago on reddit.

It had a few really cool commands that I honestly didn't know about:

disown

Ever been in a situation where you'd like to turn off your laptop, but you just started a long lasting process and forgot to use screen? disown to the rescue:
$> long-lasting-command-that-you-dont-want-to-wait-for.sh
^Z
[1]+  Stopped        long-lasting-command-that-you-dont-want-to-wait-for.sh
$> bg
$> disown
^D
# Process still lives, although terminal is disconnected

fc

How about those simple one-liners that somehow always turn out to
be so long that they really should be done as a script on file instead?
$> ls | perl -nle 'started-out-short-and-neat-but-now-long-and-complex-oneliner'
$> fc
# Opens your $EDITOR and pastes the last command used, ready to be edited and saved!

cd -

cd - is a small little gem that basically changes your current path to
you previous directory (see also pushd and popd):
$/very/long/path/to/somewhere > cd /another/very/long/path/to/somewhere
$/another/very/long/path/to/somewhere > cd -
$/very/long/path/to/somewhere >
You can also use it to copy something from your previous directory:
$/very/long/path/to/somewhere > cp `cd -`/file.txt .

units

This one speaks for it self:
$> units "100 kg" stones
    * 15.747304
    / 0.063502932

OSX Bonus

For OSX users I tend to find pbcopy and pbpaste really usefull for copying and pasting to the clipboard:
$> ls *.jpg | pbcopy
# Copy file-list to clipboard

I also discovered that my soon-to-be-collegaue +Adam Ohren made a cool tool
called pbfcopy that does the same as pbcopy only for files. Nice!