A look at some command line tools unique to OS X / Darwin
OS X (Darwin) contains several tools that aren't included in any other UN*X operating system, and some of them are actually more useful than their GUI counterparts. Keep in mind that this list is not intended to be a complete list of unique command line tools, it's just a collection I've found useful.
All of these were found on OS 10.4.10, and I can't vouch for their existence on other versions.
Each command name contains a short description of what the man page says and some commentary.
NEW: What's new in Leopard. I just diff'd /bin, /sbin, /usr/bin and /usr/sbin. Here's the rundown on cool new stuff in Leopard:
diskutil
"diskutil manipulates the volume-level structure of local disks. It provides information about, and allows the administration of, the partitioning scheme of disks, optical discs, and AppleRAID sets."
What this means is that you can mount, unmount and eject disks, enable or disable journaling (on filesystems that support it) and fsck or repair permissions on a volume. Apparently does all kinds of RAID magic too.
ditto
"Copy directory hierarchies, create and extract archives."
Happy fun joy, an equivalent to cp that actually preserves HFS+ metadata.
drutil
"Interact with CD/DVD burners."
Has options like bulkerase, which will continuously erase any inserted RW media until you ^C the process. Also lets you display some more arcane data (subchannels, CDTEXT etc) about the drive or inserted disk
hdiutil
"Manipulate disk images (attach, verify, burn, etc)."
Great for monkeying around with DMG files. Allows you to do all kinds of funky things like create a shadow file for a read-only disk image, so all data written to the attached image goes into the shadow file.
installer
"System software and package installer tool."
Allows you to install PKG files via the command line or view information about a specific PKG file.
lipo
(no man page)
Judging from the name (ha ha, I see what you did there, Apple) and a bit of experimentation, you can thin a "fat" binary with lipo. Here's an example:
MKDCXLIII:~ orbat$ lipo -detailed_info /Applications/Adium.app/Contents/MacOS/Adium
Fat header in: /Applications/Adium.app/Contents/MacOS/Adium
fat_magic 0xcafebabe
nfat_arch 2
architecture ppc
cputype CPU_TYPE_POWERPC
cpusubtype CPU_SUBTYPE_POWERPC_ALL
offset 4096
size 2020468
align 2^12 (4096)
architecture i386
cputype CPU_TYPE_I386
cpusubtype CPU_SUBTYPE_I386_ALL
offset 2027520
size 2048668
align 2^12 (4096)
MKDCXLIII:MacOS orbat$ lipo -thin i386 /Applications/Adium.app/Contents/MacOS/Adium -output /Applications/Adium.app/Contents/MacOS/Adium
MKDCXLIII:MacOS orbat$ lipo -info Adium
Non-fat file: Adium is architecture: i386
(fat_magic has me giggling every time. Not to mention the fact that it's set to 0xCAFEBABE)
mdfind
"Finds files matching a given query."
An interface to Spotlight. Since the annoying bastards left out Boolean searches from the Spotlight GUI, you can get back at them and use mdfind. Here's a couple of examples
mdfind "foo bar" both foo and bar must appear in the file
mdfind "foo|bar" either foo or bar must appear
mdfind "(-foo)bar" bar must appear, but without foo
Note that you have to use the quotes.
the -onlyin option makes mdfind search only the specified directory.
You can also include metadata attributes in the search, like so
mdfind "foo (kMDItenFSName == 'bar*')"
This would find a file that has "bar" in the beginning of its name and contains the text "foo." You can find out about different metadata attributes by using the mdls utility. It seems that you can use at least == < > when comparing the attributes to something, != (or actually \!= since I had to escape the bang) didn't work in my test cases.
mdls
"Lists the metadata attributes for the specified file."
Pretty straightforward. Here's what happened when I ran it on a text file
kMDItemAttributeChangeDate = 2007-02-04 15:07:58 +0200
kMDItemContentCreationDate = 2007-02-04 14:55:04 +0200
kMDItemContentModificationDate = 2007-02-04 15:07:49 +0200
kMDItemContentType = "public.plain-text"
kMDItemContentTypeTree = (
"public.plain-text",
"public.text",
"public.data",
"public.item",
"public.content"
)
kMDItemDisplayName = "fmarkov.txt"
kMDItemFSContentChangeDate = 2007-02-04 15:07:49 +0200
kMDItemFSCreationDate = 2007-02-04 14:55:04 +0200
kMDItemFSCreatorCode = 0
kMDItemFSFinderFlags = 0
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSLabel = 0
kMDItemFSName = "fmarkov.txt"
kMDItemFSNodeCount = 0
kMDItemFSOwnerGroupID = 501
kMDItemFSOwnerUserID = 501
kMDItemFSSize = 5494
kMDItemFSTypeCode = 0
kMDItemID = 3567987
kMDItemKind = "Plain text document"
kMDItemLastUsedDate = 2007-02-04 15:07:58 +0200
kMDItemUsedDates = (2007-02-04 14:55:04 +0200, 2007-02-04 02:00:00 +0200)
plutil
"Property list utility."
You can use it to convert a binary plist file to plain ole XML (or the other way around) or check the syntax of the file.
pbcopy, pbpaste
"Provide copying and pasting to the pasteboard (the Clipboard) from command line."
What the man says. Copies or pastes using stdin. They're especially useful since you can do things like ps auxwww | pbcopy
pmset
"Manipulate power management settings."
Allows you to change power management stuff, but what I found the most useful was changing the disk spindown timer.
screencapture
"Capture and manipulate clipboard contents."
The man page makes screencapture seem like a clipboard utility, but it's (surprisingly enough) actually an utility for making screen captures in various ways. Very, very useful. If you run it on a remote machine (when logged in with, say, ssh) you need to jump through a couple of hoops, but it's still very useful nonetheless.
security
"Command line interface to keychains and Security.framework."
Allows you to do just about anything the Keychain Access app allows you to do.
sips
"Scriptable image processing system."
Allows you to mangle pictures in interesting ways like scaling, rotating, flipping, pad to fit a certain size, change the color profile etc.
textutil
"Text utility."
Thank you Captain Obvious. textutil is actually a command line interface to a part of the Cocoa text system. It allows you to, for example, convert different kinds of text files to other formats (it can cope with TXT, HTML, RTF, RTFD, DOC, wordml and webarchive) or concatenate different files into a single file with using format you specify.
Front page.