It's been a few years since the release of the book I co-wrote with Ernie Rothman, Mac OS X for Unix Geeks, and I see that a few things have changed since I originally offered the top 10 tips that I gathered while working on the book. 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 ports of popular open source applications.
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, tcshbash. 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.
2. Sudo, Not Su
By 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 Administrative 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.
To get compilers and many other development tools, you'll need the Mac OS X Developer Tools. If you bought the boxed version of Mac OS X, the Developer Tools should be included on a separate CD-ROM. If you bought a new Macintosh that came with Mac OS X preinstalled, the Developer Tools installer will probably be in /Applications/Installers. Failing either of those, or if you'd like to get the latest version of the tools, they are available to Apple Developer Connection (ADC) members.
3. Startup
Mac OS X startup 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 via /System/Library/StartupItems (for system startup items) or /Library/StartupItems the launchd startup program. You can read all about it in this ADC article.
4. Filesystem Layout
If 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.
The following table lists some of these folders that you'll see (Appendix A of Mac OS X for Unix Geeks contains a more comprehensive list):
File or Directory
Description
.DS_Store
This file contains Finder settings.
.Spotlight-V100
This file contains Spotlight settings.
.Trashes
This directory contains files that have been dragged to the Trash.
.fseventsd
Used by the File System events framework.
.hotfiles.btree
This is used by Mac OS X's Hot-File-Adaptive-Clustering feature to keep track of frequently used files.
.vol/
This directory maps HFS+ file IDs to files.
Applications/
This directory holds all your Mac OS X applications. Check out its Utilities/ subdirectory for lots of fun stuff!
Desktop DB, Desktop DF
The Classic Mac OS desktop database.
Desktop Folder/
The Mac OS 9 desktop folder.
Developer/
Apple's Developer Tools and documentation. Only available if you have installed the Developer Tools.
Library/
Support files for locally installed applications, among other things.
Network/
Network-mounted Application, Library, and Users directories, as well as a Servers directory.
Shared Items/
Use by Mac OS 9 to share items between users.
System Folder/
The Mac OS 9 System Folder.
System/
Contains support files for the system and system applications, among other things.
Temporary Items/
Temporary files used by Mac OS 9.
TheVolumeSettingsFolder/
This directory keeps track of details such as open windows and desktop printers.
Trash/
Mac OS 9 trash folder.
Users/
Home directories.
VM Storage
Mac OS 9 virtual memory file.
Volumes/
Contains all mounted filesystems.
automount/
This directory handles static NFS mounts.
bin/
Contains essential system binaries.
cores/
If core dumps are enabled (with tcsh's limit and bash/sh's ulimit commands), they will be created in this directory as core.pid.
dev/
This directory contains files that represent various devices.
etc/
This directory contains system configuration files.
mach
This is a symbolic link to the /mach.sym file.
mach.sym
Kernel symbols.
mach_kernel
The Darwin kernel.
private/
Contains the tmp, var, etc, and cores directories.
sbin/
Executables for system administration and configuration.
tmp/
Temporary files.
usr/
This directory contains BSD Unix applications and support files.
var/
This directory contains frequently modified files such as log files.
5. Different Kinds of Hidden Files
As 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 command, as in SetFile -a V SomeFile. (The SetFile command is available in /Developer/Tools after you install the Mac OS X Developer Tools package described in the sidebar.) 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 are only invisible from the Finder; you can still see them with ls.)
6. Aliases and Links
There are two ways to create links to files. The first is to select the file in the Finder, and drag it to a new location while holding down the Option and Command 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.
7. X11
Mac OS X does not come with the X Window System. For native applications, it uses an advanced graphics system called Aqua. But if you want to run X11 applications, you're in luck: Apple has its own X11 implementation with nice Aqua integration, and there is an installer for it on your Mac OS X installation CD-ROM or DVD. If it wasn't installed by default, run the Optional Installs package on your install disc. You'll be able to run X11 applications side-by-side with Mac OS X applications, and they'll look great.
8. Fink
Are there some Unix or Linux applications that you're missing? Check out the Fink project, which modifies open source applications so they'll compile and run on Mac OS X. Fink already includes an impressive array of applications, and more are on the way.
Related Reading
Mac OS X for Unix Geeks
By Brian Jepson, Ernest E. Rothman
+
9. /etc is Not Always in Charge
If you've come to Mac OS X from another Unix, you may expect that you can add users and groups to the /etc/passwd and /etc/group files. By default, Mac OS X only uses these file in single-user mode. If you want to add a user or group, it will need to go into the Directory Services database, a repository of local directory information. For more information, see this ADC article,Open Directory and the dscl Tool.
10. Shutdown Doesn't Really
For a long time, Mac OS X couldn't execute custom actions at shutdown. The SystemStarter framework (which predates launchd) can perform custom shutdown actions when the system is shutting down. For more information, see "Start Me Up: Writing and Understanding OS X StartupItems" (the ADC launchd article mentions that services that need an explicit shutdown procedure will need the old SystemStarter framework).
No comments:
Post a Comment