Tiny Deathstars of Foulness

Sometimes when I’m writing a script, I need something to phone home to something in the script. For example, this can tell another daemon where to ssh into when I invoke it remotely. So, let’s say I want to grab my WAN address in a script. I can use curl with a number of 3rd party sites (sites that often change. But, one that we can use here is Here, we’ll look at their plain output page here:


This can then get output into a variable or file for processing in other parts of a script. For example, the output here is basically the same thing but the command is in backticks, as you might put it in when scripting:

echo `curl`

July 26th, 2015

Posted In: Mac OS X, Mac OS X Server, Mac Security, Ubuntu, Unix

Tags: , ,

The at command can be used to schedule jobs to be run at certain times. I have a hard time getting up in the morning. Here, we’re going to echo a command that we want to be run at a certain time. In this case, we’re going to open a song to make into our alarm clock:

echo 'open ~/Desktop/bangbang.m4v 2>/dev/null' | at 07:00 tomorrow

The job will then output. You can see jobs waiting to be run, along with when they’ll be run using the at command with the -l option:

at -l

In this case, the job is 2. You can then remove a job using the atrm command:

atrm job 2

July 23rd, 2015

Posted In: Mac OS X, Ubuntu, Unix

One of the great things about cat is that you can view the contents of a file with line numbers. You do so using the -n option, as follows:

cat -n ~/Desktop/myFile

Sometimes a file is too big to view though, so you can pipe the output to less, to combine some of the best features of each:

cat -n ~/Desktop/myFile | less

Obviously, the same thing would work with more:

cat -n ~/Desktop/myFile | less

You can also do something similar with the grep command and the -n option:

grep -n ^ ~/Desktop/myFile | less


July 21st, 2015

Posted In: Mac OS X, Ubuntu, Unix

Tags: , , ,

The cd command has lots of fun little shortcuts. One I use frequently is the -. The ~ always takes you to your home directory, but using cd – will take you to the last directory you were in. For example, if you do the following on a Mac:

cd ~

Then you do .. (which is a shortcut for the directory above the one you’re in):

cd ..

Then pwd will show that you’re in /Users. But, if you cd to – again:

cd -

Now you’re back in your home folder. The – expands to OLDPWD. Quick tip. Nothing more to see here.

July 20th, 2015

Posted In: Mac OS X, Ubuntu, Unix

Tags: , , , , ,

The ffmpeg command is pretty rad. I’ve written about it before, but now I’m using it to rip the audio out of video podcasts that don’t need video. Extracting an mp3 from video that doesn’t need any video means I can have way more on my iPhone. So here goes:

ffmpeg -i randopodcast.flv -vcodec mpeg2video randopodcast.m2v -acodec copy randopodcast.mp3

The video is pretty irrelevant for what we’re trying to do, but it’s great to have smaller files and more of ’em!

July 14th, 2015

Posted In: Mac OS X Server, Ubuntu

Tags: , , , ,

The mkdir command is used to create directories. Sometimes, in testing, you need to have a lot of directories. So, you can use the following command to create 10,000 5 digit directories, named 00001 to 10000:

mkdir $(printf '%05d\n' {1..10000})

July 13th, 2015

Posted In: Mac OS X, Mac OS X Server, Mac Security, Ubuntu, Unix

Tags: , , , ,

The following command will remove all empty lines from a file called

sed '/^$/d'

July 12th, 2015

Posted In: Mac OS X, Mac OS X Server, Ubuntu

Tags: , , , ,

You see a lot of entries for various things in log files. Here, we’re going to print out the number of entries with backupd in them:

awk '/backupd/{print NR}' /var/log/system.log

July 11th, 2015

Posted In: Mac OS X, Ubuntu, Unix

Tags: , , , , , ,

The wc command is used to count words, characters and lines. Here, we’ll run it a few different ways. -l shows the number of lines in a file. For example, in my home directory, I can use it to see how many lines are in my .gitconfig file:

wc -l .gitconfig

This would output something like the following:

11 .gitconfig

Or count the number of characters with -c:

wc -c .gitconfig

Or check the number of words:

wc -w .gitconfig

You can also run it against multiple files. For example, here I’ll check the number of lines in both my .gitconfig file and my .gitignore_global files:

wc -l .gitconfig .gitignore_global

Let’s say I have a list of numbers and I want to take an average of them. I can use this to quickly figure out how many numbers I have (and so will divide by) before tallying them up.

July 4th, 2015

Posted In: Mac OS X, Ubuntu, Unix

Tags: , , , , , , ,

You can redirect a log file into a given directory. That directory, if it has other stuff in it, can get out of control. So, here, we’re going to remove all files except that file using the find command:

find * ! -name jamf.log -type f -delete

Once run, the jamf.log is the last file left in the directory.

June 28th, 2015

Posted In: Mac OS X, Mac Security, Ubuntu, Unix

Tags: , , , ,

« Previous PageNext Page »