Useful GeekTool UNIX commands

Useful GeekTool UNIX commands

GeekTool is a fabulously easy way of displaying images from the web and the output of UNIX commands on your Mac’s desktop. These are my frequently-used commands.

NOTE: We use two kinds of quote marks here:

  1. the straight quote ' to delimit a text string
  2. the back-quote (or back-tick) ` which causes the string within to be executed as a command and the results returned

Time elsewhere

How to keep track of coworkers in India; when’s their day and night? They’re 12.5 hours ahead of where I was in California. So I hard-coded the offset values:

`date -j -v+12H -v+30M +'India %a %H:%M'`

which returns India Fri 10:36

A better, proper, portable way is to specify the actual timezone in which you’re interested.

TZ=':Asia/Calcutta' date +'India %a %H:%M'

So when you pick up your laptop and travel through a bunch of timezones, and your local time changes, the hardcoded offset doesn’t steer you wrong.

Currently I have a cascading bunch of these displaying a list of times in which I’m interested. No reason to repeatedly show the minutes on each line, it’s the same as the time in this timezone.


TZ=America/Los_Angeles date +"PST %H"; TZ=America/New_York date +"EST %H" ; TZ=Asia/Dubai date +"Dubai [%a] %H" ; TZ=Asia/Kolkata date +"Kolkata ~ biomorf.in [%a] %H" ; TZ=Asia/Jakarta date +"Jakarta ~ biomorf.id [%a] %H" ; TZ=Asia/Shanghai date +"Chengdu ~ vantron [%a] %H" ;

Days since a special date

How to calculate – on one line – the number of days that have passed since a particular date?

echo \( `/usr/local/bin/gdate +%s --date=today` - `/usr/local/bin/gdate +%s --date=2012-08-26` \) / 86400 | bc

This required a bit more than a stock macOS; get GNU date with brew install coreutils

macOS swap files

There was a time when macOS did a bad job of cleaning up swap files. At about seven things started swapping, paging, and hanging, so I kept track of them and rebooted before I visited that bad place.

ls -l /var/vm | grep swapfile | wc -l

uptime, natural language style

Want to see how long since your last reboot, your “up time”, in an easy-to-read natural language style, like 2 days 16 hours 38 minutes? The following very long command does the trick:

uptime | cut -d ' ' -f 4- | rev | cut -d ' ' -f 8- | rev | sed -e 's/,$//' -e 's/:/ hours /' -e 's/\([0-9]$\)/\1 minutes/' -e 's/,[ \t]/ /g'

Monthly calendar blocks

cal_head=`cal | head -1`; cal_tail=`cal | tail -7`; today=`date '+%e'`; echo '$cal_head'; echo '${cal_tail/${today}/\033[1;32m${today}\033[0m}';

generates a one-month calendar block with the current day highlighted, if your terminal supports that sort of thing.

June 2016
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30

To get the next or past month(s), use something like:

cal `date -v +1m '+%m %Y'`

Top CPU usage, as simple as possible, sorted

Under macOS, the command I use to see a one-time list of the top CPU consumers and the percentage, sorted with hungry apps above, is:

ps -racwwwxo 'command %cpu' | head -20

A truncated sample output:

COMMAND %CPU
WindowServer 8.1
MacDown 5.4
iTerm2 4.5

UTC time

UTC – Universal Coordinated Time – is the shared abstract time scale that came into being with atomic clocks. Note that it’s not a timezone, unlike GMT (Greenwich Mean Time), a term referring to mean solar time at the Royal Observatory, Greenwich, England, where a system was first developed around 1850 for tracking time based on the rotation of the Earth.

Displaying UTC in 24-hour format:

date -u +'%R'

iCalBuddy formatting

iCalBuddy displays the contents of your Apple Calendar database with a remarkable range of formatting options.

/usr/local/bin/icalBuddy -sd -ss ' ' --includeCals 'Calendar' --excludeEventProps 'notes,url,location,attendees' -npn --formatOutput --noCalendarNames --propertySeparators '/ » /' --timeFormat '%H:%M' --dateFormat '%A %m/%e' eventsToday+10 | sed -e 's/day 0/day /g'

Shows my appointments and times in a most compact, easy-to-read fashion. Actual output is colorized by calendar.

today:
• Demo » 10:00 - 10:30
• Cold Tea » 13:00 - 14:00

Monday 6/13:
• Some Thing » 11:30 - 12:00

Tuesday 6/14:
• Status Updates (stand-up) » 08:00 - 08:30
• Show and Tell » 12:00 - 13:00
• Release Prep » 15:30 - 16:00

Well then, there you have it. I’ll add new commands as I stumble across a need for them. Share and enjoy.