Author Brian Jepson offers the top 10 tips he gathered while working on O'Reilly's Mac OS X for Unix Geeks. These tips will show you the differences between Mac OS X and other flavors of Unix, help you find the bits that resemble the Unix you are used to, and even feather your nest with XFree86 and ports of popular open source applications. 56.1 1. Where's My Shell?A Unix geek won't get too far without a shell, right? You can find the Terminal application by navigating to /Applications/Utilities in the Finder. Drag the Terminal application to your Dock so you can access it quickly. When you start up the Terminal, you'll be greeted with the default user shell, tcsh. You can customize the Terminal's appearance and settings by selecting Window Settings from the Terminal menu. You can set the startup shell by selecting Preferences from the Terminal menu. 56.2 2. sudo, Not suBy default, the root user is disabled on Mac OS X. If you need to do something as root, use the sudo command. To use this command, pass in the command and arguments you want to execute, as in sudo vi /etc/hostconfig. You'll need to be a user with administrator privileges. The main user has this capability by default. If you need a root shell, you can always use sudo tcsh or sudo bash. If you want to enable the root user, it's as simple as giving root a password with sudo passwd root. You'll also want to open System Preferences, choose Accounts, then Login Options, and change "Display Login Windows as" to Name and Password. Then you can log out and log in as the root user. 56.3 3. StartupMac OS X startup [Hack #13] is nothing like other Unix systems. Most significantly, Mac OS X has nothing like the /etc/init.d directory. Instead, it finds its startup items in either /System/Library/StartupItems (for system startup items) or /Library/StartupItems (for locally installed startup items). You can use existing startup items as a template or check out Mac OS X for Unix Geeks for detailed instructions. At a minimum, you need to:
After you've done these steps, you can start the service with SystemStarter, as in sudo SystemStarter start MySQL. 56.4 4. Filesystem LayoutIf you open up a Finder window to the top level of your hard drive, you'll see that familiar friends like /var and /usr are missing. They are actually hidden (more on that later). If you open up a Terminal shell and do an ls /, you'll see the missing folders, as well as a few others, such as /Library and /Developer. Table 5-1 lists some of the folders that you'll see (Appendix A of Mac OS X for Unix Geeks contains a more comprehensive list).
56.5 5. Different Kinds of Hidden FilesAs with other Unix flavors, you can make a file invisible by prefixing its name with a ., as in /.vol. This has the effect of making it invisible in the Finder, as well as when you issue an ls without the -a option. Mac OS X also uses a file in the root directory (.hidden) to maintain a list of files that should be hidden from the Finder. Also, HFS+ (the filesystem used by Mac OS) files and directories can have a hidden attribute set using the SetFile[Hack #6] command, as in SetFile -a V SomeFile. This setting won't take effect until you relaunch the Finder. You can log out and log in again or use the Force Quit option from the Apple menu. You can turn off the invisible bit with SetFile -a V SomeFile. See the manpage for SetFile for more details. (Note that invisible files set this way are invisible only from the Finder; you can still see them with ls.) 56.6 6. Aliases and LinksThere are two ways to create links to files [Hack #9]. The first is to select the file in the Finder and drag it to a new location while holding down the Option and keys (or select Make Alias from the File menu). This creates a Mac OS alias that Cocoa, Carbon, and Classic applications can follow. However, Unix applications will ignore those links, seeing them as zero-byte files. You can also create a link with ln or ln -s. If you use this kind of link, Unix, Cocoa, Carbon, and Classic applications will happily follow it. 56.7 7. X11Mac OS X does not come with the X Window System. Instead, it uses an advanced graphics system called Aqua. But if you want to run X11 applications, you're in luck: XFree86 has been ported to Mac OS X. You should first download and install XDarwin (http://www.xdarwin.org), which provides the X Server and essential tools. The next step is optional. OroborOSX (http://oroborosx.sourceforge.net/) is an X11 window manager with an Aqua look and feel. You'll be able to run X11 applications side-by-side with Mac OS X applications, and they'll look great.
56.8 8. FinkAre there some Unix or Linux applications that you're missing? Check out the Fink project (http://fink.sourceforge.net), which modifies open source applications so they'll compile and run on Mac OS X. Fink [Hack #58] already includes an impressive array of applications, and more are on the way. Other porting projects that you should explore include DarwinPorts (http://www.opendarwin.org/projects/darwinports/) and GNU-Darwin (http://gnu-darwin.sourceforge.net/). 56.9 9. /etc Is Not Always in ChargeIf you've come to Mac OS X from another Unix OS, you may expect that you can add users and groups to the /etc/passwd and /etc/group files. By default, Mac OS X uses these files only in single-user mode. If you want to add a user or group, it will need to go into the NetInfo database, a repository of local directory information. The quick way to add a user or a group is to feed a record in either the passwd or the group format into niload (commands you type are shown in bold; the ? is used by the here-document syntax that starts with <<EOF and ends with EOF): % sudo niload passwd . <<EOF ? rothman:*:701:20::0:0:Ernest Rothman:/Users/rothman:/bin/tcsh ? EOF After you've created the new user, you need to set the password, use the ditto -rsrc command (a copy command that preserves HFS+ resource forks when accompanied by the -rsrc flag) to create the home directory, and set permissions correctly: % sudo passwd rothman Changing password for rothman. New password: ******** Retype new password: ******** % sudo ditto -rsrc \ /System/Library/User\ Template/English.lproj \ /Users/rothman % sudo chown -R rothman:staff /Users/rothman 56.10 10. Shutdown Doesn't ReallyAt the time Mac OS X for Unix Geeks was written, we had indications that Jaguar (Mac OS X 10.2) would execute the shutdown actions in the scripts contained in /System/Library/StartupItems and /Library/StartupItems. As it turns out, it doesn't. So, if you are running a sensitive application such as a database server, be sure to shut it down manually before you shut down your computer. It's disappointing that Mac OS X does not include the facility to gracefully shut down daemons when the system is powered down. However, the infrastructure is present, and we hope it's switched on in a future update. Brian Jepson |