The Living Thing / Notebooks :

Unix commands I need often

but which are tedious to work out

General, not OSX-specific or linux-specific, and see also shell scripting to yak-shave your way into who other shell paradigms or….


Command lines to command your command lines:

OK, time for actual commands I need to remember now…

I suppose if I were a good person I’d submit the following to tldr or bro pages or version my .cheats folder in my dotfile repo, but I’m now exhausted and just want to go home.

Surviving bash

Basic syntax.

I just don’t care enough to remember. This makes me a Bad Hacker.

For loops

Watch out for horrible problems with handling of delimeters. Anyway, for loops are not insane.

for i in $( ls ); do
    echo item: $i

bash history

sync only if drive present

test -d  /Volumes/syncdrive/ && rsync --delete -avz \ /Volumes/syncdrive/

Renames and copies

files extension munging in bash

mv "$file" "`basename $file .html`.txt"


mv "$file" "${file%.html}.txt"

Don’t forget the quotes, or it will explode when you have spaces in your filenames and delete stuff that you loved. (I hate bash so hard. I should probably abandon it.)

No, actually don’t do that in naked shell. Use…


rename is a script that makes renaming work how you imagine it should.

rename -s html txt *.html


Trailing whitespace

A shell script to remove trailing whitespace from a file - put this in

# OSX version
sed -i '' -e's/[[:space:]]*$//' "$1"
# GNU version
sed -i -e's/[ \t]*$//' "$1"

Then you can trim trailing whitespace from your… whatever… by putting this line in there:

find . -type f -print0 | xargs -0 -I {} \{\}