August 19, 2013

A Clutch of Homebrew Unix Utilities

Filed under: Main — admin @ 12:01 am

I just can’t stop programming! Ever since DOS, when I wrote handy utilities in BASIC (and then in Assembly and then in C), I want to code some handy little shortcut or interesting little problem-solver.

My programming frenzy isn’t as necessary on the Mac. That’s because Unix has a clutch of handy utilities all ready to go. In fact, my goal now is to first scour the Unixverse to see whether or not the problem I have has already been solved. I don’t even want to get into all the various language tools available, sed, awk, perl — Unix is a rich environment.

Even given the vast assortment of available utilities, I’ve felt the need to write my own. These programs dwell in my personal bin folder:

ascii. This program dumps out the ASCII code, columns of characters, decimal, and hex values. It saves me time from looking up the codes in the back of my books. It’s also reminiscent of the ASCII table that was once a part of the old Sidekick utility. Anyone remember that?

filename. This program swallows a filename as an argument, but removes the extension. Yes, I know that I could write a sed or awk script to do the same thing. Instead, I coded it in C. I forget why I needed to know the filename without the extension, but it was a high enough need that I coded my own utility.

gang. This is a full-screen file renaming utility that I wanted to write for a long time. As an author, I name documents with their chapter numbers, 01.doc through 27.doc or whatever. Occasionally I need to move things around, which requires massive file renaming duties. My gang utility lets me rename a gang of files all at once, in sequence. Screenshot shown in Figure 1.

Figure 1. The 'gang' program lets me rename/renumber files en masse.

Figure 1. The ‘gang’ program lets me rename/renumber files en masse.

hello. An amusing script. When I’m bored I often type hello at the prompt. This utility directs the Mac’s voice synthesizer to say, “Hello, Dan? Are you bored?”

icf. This program is a filter that takes standard input and capitalizes the first letter of every word. I have no idea why I wrote it.

lfname. This utility was born when I began transferring my writing archives to the Mac. It takes the ALL CAPS filenames generated from Windows and turns them into lower case. It’s essentially a gang-rename program: Run lfname in a directory and all the files are renamed to lower case.

mkdate. Perhaps my most favorite utility, mkdate generates a text string based on the current date. Without any arguments, the current date is produced, such as 20130819. You can specify a formatting string as an argument to get the date output specifically (including month and weekday names), and include other text in the output as well. Two switches control the output: One suppresses the newline and the other prefixes any whitespace with a backslash.

The reason I wrote mkdate is for archiving. I use it to create a folder named after the current date. I also use mkdate when building backup files. It’s pretty handy.

now. A copy of my old DOS utility, it spits out the current date and other trivial information. Here’s sample output:

Today is Wednesday, August 21st 2013. It is the 233rd day of the year.
The time is now 10:23:40 AM in the PDT timezone.
The moon is waxing gibbous.

path. A perl script, this utility spits out the current search path.

reader. I wrote this full screen utility to view screenshot files I took for my old DOS books. I forget the name of the screen capture utility, but it was pretty easy to figure out how the text screen was stored. Below you see a sample from my book Working With Magellan, published in 1990.

Figure 2. A rendering of the screen shot for Figure 6-1. Extended ASCII text appears using asterisks.

Figure 2. A rendering of the screen shot for Figure 6-1. Extended ASCII text appears using asterisks.

skip. A filter that reads every nth line from standard input and sends it to standard output. Without an argument, every other line is skipped. Again, I have no idea why I wrote this.

width. My notes in the source code say that I needed this utility “today” and didn’t explain why. The program reads an entire text file. It outputs the widths of the longest line and the shortest line. I believe that the awk utility may be configured to perform that kind of magic, but I’m not good enough at awk to code it.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.


Powered by WordPress