Take Command of Terminal (Mac OS X 10.5)
OS X 10.5 brings a number of changes to its Unix core, perhaps more so than any prior OS X release. Many of the changes are routine—newer versions of key Unix programs such as the bash shell (from 2.0.5b to 3.2), the vi text editor (from version 6.2 to 7.0), and even the man manual page reader (from 1.5o1 to 1.6c). Most of these version changes will be invisible to the casual Terminal user. More interesting, however, are the totally new (or substantially revised) Unix commands that can be found in 10.5.
Those Pesky Dot-Underscore Files
If you’ve ever used a USB stick to move files to a Windows or Linux machine, or written files to a non-HFS server, you’re probably very familiar with the “dot files” that are created when you
do so—depending on what you did to the files and folders on the Mac, you’ll see any number of files whose names begin with dot-underscore (._), followed by the name of other folders on
the disk. The Mac uses these files on your HFS disk, but they’re useless on non-HFS systems. Prior to 10.5, you had to manually delete dot-underscore files on the other system, or use Terminal trickery to remove them on the Mac prior to copying. As of 10.5, though, you can just
use the dot_clean command on the directory in question. Type dot_clean "full path to folder", and the dot-underscore files will be joined with their parent files. You can read the manual pages (man dot_clean) for more information on this program.
Learn About Kernel Extensions
Kernel extensions (also known as kexts) are low-level pieces of code that talk directly to the heart of the Mac operating system. They are very powerful, and potentially dangerous: if there’s
a bug in a kernel extension, it can crash your Mac. (At worst, a buggy application can crash only itself.) In 10.5, you can use the kextfind command to find out which kernel extensions are on your machine. Most of the kernel extensions on your Mac are bundled with OS X; you can see exactly what’s installed by using this command:
kextfind -case-insensitive -bundle-id
-substring ‘com.apple.’ -print | more
While that command may look intimidating, it’s pretty straightforward. The -case-insensitive argument tells the system to find all matches, regardless of capitalization. Next, -bundle-id and -substring tell kextfind to look for the text string ‘com.apple.’ in the extension’s bundle identifier.
The print switch tells kextfind to output the results to the screen, while | more tells Terminal to pause after each page of output. You can see a list of third-party kernel extensions by inserting -not before bundle-id in the command above. Just because an extension is listed, however, doesn’t mean it’s active. To see which of your third-party extensions are active, type the following (include a space after -id):
kextfind -loaded -not -bundle-id
-substring ‘com.apple.’ | more
This is basically the same command as before, with the addition of the -loaded flag to list only those extensions that are currently active. If you’re experiencing kernel panics, this list is a good place to start looking for suspects—try removing the device or program associated with the extension and rebooting. If the kernel panics vanish, you’ve found the source of the problem. To find a lot of good examples of other uses for this command, check the man kextfind manual pages.
Dig into Installer Packages
Apple’s installer keeps track of things it installs—you can see everything it’s done by looking at the /Library/Receipts folder. From there, you can dig into packages and see what’s been installed. However, rooting around in that folder by hand isn’t a lot of fun—lots of cd and lsbom commands are required. 10.5’s new pkgutil command makes things much simpler. To see a list of installed packages, just type pkgutil –pkgs and press return. Each entry in the list represents a package ID, and you can use that string to get more information on that particular package. For instance, if you’d like to know every file the recent security update installed, just type this command and press return:
pkgutil –files com.apple.pkg.update.
security.2007.009 | more
Set System and Network Preferences
OS X 10.5 includes two good utilities, systemsetup and networksetup, that you can use to view and configure various network and machine-wide System Preferences settings. These programs aren’t actually new in 10.5; they were available in 10.4, too. But in 10.4, they were buried deep in the System folder. As of 10.5, Apple has placed them in a standard Unix folder, making them easily accessible to everyone. So just what can you do with them, and why would you want to do those things? One way these programs are useful is in managing remote connections. Say you’ve used ssh to connect to a remote Mac. You might then need its Ethernet card’s MAC address to set up a router. To get that information, just type sudo networksetup -getmacaddress en0. (You’ll need sudo for some options with these commands, as they require administrative privileges.) Want to see what network services are available on the remote Mac? Try typing networksetup -listallnetworkservices. You can then use the names of the services returned in other commands, such as this one, to display the DNS servers on the remote Mac: sudo networksetup –getdnsservers "ethernet 1" If you then wanted to change those DNS servers, you’d use the -setdnsservers option. The systemsetup command has similarly interesting abilities. For instance, you can see the sleep settings for your computer and display with either of these two commands:
systemsetup -getcomputersleep
systemsetup –getdisplaysleep
To change the display sleep setting to four minutes, you’d type systemset -displaysleep 4. You can see which disks will start up the Mac by typing systemsetup -liststartupdisks. You can also change a startup disk with the -setstartupdisk option; you follow this option with the path to that disk’s CoreServices folder, as displayed in the -liststartupdisks option. Both of these commands have lots of additional features— check out man systemsetup and man networksetup for a very thorough explanation of all of their capabilities.
Directory Services
First and foremost, if you’ve previously used the NetInfo commands (niutil, niload, and so forth) in prior releases of OS X, prepare yourself for a change—they no longer exist in 10.5. Instead, you’ll be using the Directory Services command-line utility, dscl. This new all-encompassing utility handles everything related to users and groups (and more) from the command line. Covering it, however, is well beyond the scope of this chapter— you can use man dscl to get a sense of everything you can do with this program. Another handy utility related to dscl, dscacheutil, is primarily of interest to Web developers and others who work with DNS, as it can be used to flush your DNS cache: dscacheutil -flushcache. (In 10.4, the lookupd command handled this function.)
Tags: Kernel Extensions, Mac OS X, Network Preferences, OS X 10.5, Setting
