Author Archives: Brock Tice

Command Line Tricks – Using mdfind and mdls in Mac OS X

Beginning with version 10.4 (“Tiger”), Mac OS X has had a powerful indexing and search engine built in. This can be used from the graphical interface, which is how most mac users interact with it. However, a command-line interface allows for some powerful searching and scripting.

This article by Andy Lester goes through the basic usage of the mdfind and mdls utilities, and gives examples of how to use them with UNIX pipes and in shell scripts.

Just as an example, to find text in any file on the system with find and grep, you’d have to do something like:
find / | xargs grep "my search string"

This would run grep on every file in the system, which is horribly inefficient and will take forever. With mdfind, you’d simply type:
mdfind "my search string"
This will use the existing search database to find the appropriate documents.

(N.B. – Spotlight cannot actually do a “phrase” search like the find/grep example above. See this story for more detail and some work-arounds.)

Mardi Gras is Not About Flashing

There’s a problem that New Orleanians often encounter when trying to encourage people to come for the Mardi Gras (said, “da Mawdi Graw”) — namely, they think it’s all about flashing (boobs for beads!).

With that in mind, I took some pictures this year to highlight the fact that it’s only that way in the French Quarter. And I’ve never been to the French Quarter during Mardi Gras, because I’m not insane. Here are some of the pictures.

Continue reading

Turning off IPV6 in Leopard

I was unable to use dial-up over my T-mobile phone until I disabled IPV6 in Leopard. The command to do that is:

sudo networksetup -setv6off <interface>

For me, interface was Bluetooth for the Bluetooth connection and the name of my phone for the USB connection. This will depend on whatever your phone calls itself over USB.

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.