Category Archives: Mac OS X

Mac OS X

UNIX Toolbox

UNIX-like operating systems are immensely powerful. They give one access to the minutest details of the operating system with command-line utilities. The major downside of command-line interfaces is that it is not readily apparent which commands are available and what they do. One can spend hours poring through man pages looking for related program names, instructions and examples to accomplish a simple task.

One way out of this is to use command references. When I first started using Linux, I bought a boxed edition of Red Hat (version 7, I think), which came with a wrist-rest sticker. This long sticker was designed to be stuck on a plastic keyboard wrist rest and contained some common BASH commands such as ls, cd, and mv, with brief examples. This was very helpful to me as a new Linux/UNIX user.

After 8 years of using and administering Linux and Mac OS X (BSD) machines, I have a pretty good handle on the command line. Nonetheless, I was very happy to find this UNIX toolbox document via nixCraft.

Some highlights that I discovered and will be employing from now on include:

  • fuser -m /home – Find out what programs have files open on the /home (or another) partition.
  • sysctl hw – get extensive hardware information on BSD (including OS X) systems.
  • dmidecode – Get BIOS information. I actually learned about this in the past two weeks. Sometimes it’s necessary to create /dev/mem (sudo mknod /dev/mem c 1 1) before this will work. One handy use for this is to get machine serial numbers without having to visit the datacenter.

These are just the most interesting examples from the first ten pages. Aside from simple commands, the document also includes instructions for complicated and infrequently-used but occasionally-necessary tasks that I never remember how to do off-hand. One could spend half an hour or so reading man
pages and HOW-TOs online to find the right incantation, or just find the precise instructions in this toolbox. Such groan-inducing operations include:

  • Mounting SAMBA partitions.
  • Mounting loopback devices such as CD images.
  • Burning CD images from the command line.
  • Converting between DOS and UNIX text file formats.
  • Basic database administration.

and several others. I plan on printing the booklet version of this PDF at lab tomorrow and keeping it at my desk and in the server room.

For possibly-NSFW (but text-only) entertainment, check out a BASH of another variety.

Comments from ‘file’ (and ‘tar’)

Occasionally when using Linux (or Mac OS X) I’ll notice a tongue-in-cheek output message from a utility. Today, it was ‘file‘, a program that uses magic numbers and other tricks to tell you about the contents of a file:


[brock@stilgar][Darwin]-(~/Workspace/RvPacing/bridge/flma2memfem)-> file bridge_w_surf.flma
bridge_w_surf.flma: ASCII text, with very long lines
[brock@stilgar][Darwin]-(~/Workspace/RvPacing/bridge/flma2memfem)->

Emphasis mine. Thanks for the commentary, file.

ADDENDUM: Just now, tar gave me this little message because I forgot to provide some source data:

[brock@stilgar][Darwin]-(~/models)-> tar cfjv bridge_iso.tar.bz2
tar: Cowardly refusing to create an empty archive
Try `tar --help' or `tar --usage' for more information.

That one, I’ve seen before.

Finding Duplicates with sort and uniq

Imagine this: You have two text files full of information, with one data entry on each line. You want to find out which lines occur in both files. Now, if the files are mostly the same, it’s probably best to use a program called diff. However, if the files are mostly different, you can use this little incantation:

cat file1.txt file2.txt | sort -n | uniq -d

This will join file1 and file2, sort the joined data -numerically, and display only the lines that are not unique (uniq -d).

This came in handy for manipulating electrode files today. Our electrode files just contain lists of node numbers. The simulator gets unhappy when you try to do things with overlapping electrodes, so in this way we were able to remove the offending overlap without too much trouble.

Wilber Loves Apple

If you are a user of the GNU Image Manipulation Program (GIMP) on OS X, and you’ve upgraded to Leopard, you’re likely to run into some snags. You should instead go here to update your X11 installation, and then here to get the appropriate version of GIMP. Note that this is the new 2.4 version, with a lot of improvements from 2.2. They also have a more “edgy” and modern-looking icon for the app.

Float vs. Double

Someone in the lab recently came to me asking for help in diagnosing a strange problem. The time output from their program was drifting inexplicably — that is, they were adding a certain increment every iteration, but the time was changing by some value slightly different from that increment. It turns out that this was because they were using single-precision floating-point (a.k.a “float”) variables. The problem did not show up right away. In fact, it would not have been an issue were they not adding an increment so very many times.

To diagnose this problem, (because I haven’t dealt with this issue in a long while), I wrote this little piece of code:
Continue reading