Hack 56 Top 10 Mac OS X Tips for Unix Geeks

figs/moderate.giffigs/hack56.gif

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 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 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. Startup

Mac 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:

  1. Create a subdirectory under /Library/StartupItems. For example, if you are setting up a startup item for MySQL, you might create the directory /Library/StartupItems/MySQL.

  2. Put a startup file in that subdirectory. It should have the same name as its parent folder, as in /Library/StartupItems/MySQL/MySQL. For an example, you can look at Mac OS X's startup item for Apache, /System/Library/StartupItems/Apache/Apache.

  3. At a minimum, add a StartupParameters.plist file to that subdirectory. Again, see an existing startup item for a template.

  4. If you used a control variable to determine whether your daemon starts at boot (Apache uses WEBSERVER), set that variable to -YES- or -NO- in /etc/hostconfig.

After you've done these steps, you can start the service with SystemStarter, as in sudo SystemStarter start MySQL.

56.4 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.

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).

Table 5-1. Mac OS X files and directories

File or directory

Description

.DS_Store

File containing Finder settings.

.Trashes

Directory containing files that have been dragged to the Trash.

.vol/

Directory mapping HFS+ file IDs to files.

Applications/

Directory holding 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. Available only 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/

Used by Mac OS 9 to share items between users.

System Folder/

The Mac OS 9 System Folder.

System/

Support files for the system and system applications, among other things.

Temporary Items/

Temporary files used by Mac OS 9.

TheVolumeSettingsFolder/

Tracks details such as open windows and desktop printers.

Trash/

The Mac OS 9 trash folder.

Users/

Home directories.

VM Storage

Mac OS 9 virtual memory file.

Volumes/

All mounted filesystems.

automount/

Handles static NFS mounts.

bin/

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/

Files that represent various devices.

etc/

System configuration files.

lost+found

Orphaned files discovered by fsck.

mach

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/

BSD Unix applications and support files.

var/

Frequently modified files such as log files.

56.5 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[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 Links

There 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 figs/command.gif 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. X11

Mac 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.

At the time of this writing, Apple has also released a beta of its own X11 system, which you can download for free from http://www.apple.com/macosx/X11.

56.8 8. Fink

Are 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 Charge

If 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 Really

At 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



Mac OS X Hacks
Mac OS X Hacks: 100 Industrial-Strength Tips & Tricks
ISBN: 0596004605
EAN: 2147483647
Year: 2006
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net