Like most other filesystems , the Mac OS X filesystem is conceptually a hierarchical tree-based structure that branches from a root. In the case of Mac OS X, the filesystem is rooted on the drive partition from which the system boots. In the typical case where you boot off the single partition of the hard drive that is in your machine, your filesystem is rooted there. If you have more than one disk drive, then the filesystem is rooted on whichever partition you boot from. Likewise, if you boot from an external disk drive or even a disk image on a network server, the filesystem will be rooted from there. Figure 3-2 shows a Finder window displaying the boot disk’s filesystem.
The structure of the Mac OS X filesystem at the root level is very strict, and almost every file that Mac OS X needs to run has a specific place within it. Some of the folders at the root of the filesystem are visible in the Finder when you click on your boot drive; others are not.
The folders at the root of the filesystem that are visible in the Finder are:
This folder contains applications that are available to all users on the system. Most applications that Apple ships for Mac OS X (such as iCal, iPhoto, and Safari) are located here. In addition, a large number of useful utility programs, such as the Terminal and Activity Monitor, are installed in the Utilities subfolder.
If you have installed the developer tools on your system, most of the applications, documentation, examples, and other files needed for building applications for Mac OS X are located here.
This folder contains application- and system-specific resources, such as fonts and application preferences, that are needed by all the users on the system. In some respects, this folder is like its namesake in that it holds a lot of useful information for the various parts of the system.
This folder contains the resources used by the operating system itself. Mac OS X is very particular about the files in this directory and will prevent you from messing with them. It’s best to consider this directory strictly Apple’s domain.
This folder contains the Home folders for the users on the system. Within a Home folder, a user is the master of her domain. Outside a user’s Home folder, the ability to make changes is greatly limited and depends on the type of user she is.
If the Classic Mac OS 9 environment is installed on your machine, you’ll also see the following folders:
This folder contains applications that aren’t designed to run on Mac OS X.
This folder contains all the files and folders that are part of the Mac OS 9 desktop. This folder is useful when you boot back and forth between Mac OS 9 and Mac OS X and need to get to the files that you left on the Mac OS 9 desktop.
This is the traditional folder in Mac OS 9 for storing your documents and is placed here for convenience. In Mac OS X, you should always use the Documents folder in your Home folder instead of this folder.
This folder contains the Mac OS 9 system and supporting files.
These folders aren’t part of Mac OS X but are located at this level of the filesystem for ease of use when you boot into Mac OS 9 from the drive.
The Finder’s view of the filesystem doesn’t reveal everything that’s there. The Finder is just one view, and for most users, it is sufficient because it keeps hidden system files, sometimes known as dot files
, from view. The Terminal (/Applications/Utilities
), however, lets you dive beneath the pretty GUI view and see everything in the filesystem. Example 3-1 shows the output of the ls
command.
Chapter 4 will give you a little bit more grounding in the Terminal. For now, just play along.
Example 3-1. The command-line view of the filesystem root
$ ls /
Applications Network bin mach.sym tmp
Desktop DB System cores mach_kernel usr
Desktop DF Users dev opt var
Developer Volumes etc private
Library automount mach sbin
As you can see, this is a much different view of the filesystem than you’ll see in the Finder. Some of the folders—Applications, Library, Network, System, and Users—are the same as those in the Finder, but many aren’t exposed. You’ll see this kind of difference time and again in Mac OS X. The GUI gives you a filtered view of the system, and most of the time, this filtered view is exactly what you want. The Terminal, on the other hand, gives the raw view of the system, providing you with unfettered access to the depths of the system.
Some of the folders and files visible using the command line at this level, but hidden in the Finder, are:
These are the hidden files behind Mac OS 9’s desktop. The Desktop folder in the Finder view uses these files to present your Mac OS 9 desktop to you while you are booted into OS X.
This virtual filesystem allows you to browse the filesystems shared from servers on your network.
This directory contains all the disks, other than the boot disk, that are attached to your computer. For example, external FireWire disks (including an iPod), as well as CDs, will show up here.
This directory contains links to any filesystems mounted from network file servers using network protocols such as AFP, NFS, and SMB.
This directory contains many of the executable Unix programs that your system needs.
This directory contains crash files for the various Unix programs. This is the traditional location in which Unix programs write out their crash data.
This directory contains the various device nodes for the system. One of the core ideas of Unix is that the various devices can be treated as files—including some devices that you normally wouldn’t think of as being a file. The dev
tree contains the “files” that represent everything attached to the operating system.
This directory contains configuration files used by the various Unix components of the system.
mach
, mach.sym
, and mach_kernel
These files make up the kernel, the core part of the operating system that manages everything else.
This directory is used to store optional Unix tools and libraries that may not be an integral or included part of Mac OS X itself. For example, Mac OS X Server places the Apache 2 web server in this folder but uses an earlier version of Apache as its default web server daemon.
This is the directory that actually contains the etc
, var
, and tmp
directories. These directories actually don’t live at this level of the filesystem but are linked into the root (/
) directory.
This directory contains system executables needed at startup as well as some configuration utilities for the system.
This is a place for the temporary files that some Unix programs create.
This directory contains the Unix tools and libraries that are intended for all users on the system.
This directory contains data that changes frequently such as mail spools and logfiles. The disk files that implement the backing store for virtual memory are also held here.
There’s actually another layer of hidden files beyond what you see with the ls
command. If you change the command and add an -a
option (to show all files), you’ll see the extra files shown in Example 3-2.
Example 3-2. Hidden files in the root directory
$ ls -a /
. .vol Network cores opt
.. Applications System dev private
.DS_Store Desktop DB Users etc sbin
.Spotlight-V100 Desktop DF Volumes mach tmp
.Trashes Developer automount mach.sym usr
.hotfiles.btree Library bin mach_kernel var
The .DS_Store
file contains the Finder settings and the comment text for the various files within the folder. The rest of these files are, well, files that you really don’t need to see. They are hidden from the command-line view, which indicates that you should mess with them only if you really need to and you know what you are doing.
Even though the Finder hides these directories from you, there is an easy way to get to them. Simply use the Go to Folder command (Go → Go to Folder, or Shift--G) and enter the path to the folder you want to see. An example of this is shown in Figure 3-3.
If you want to see every file on your system all the time, you can do so by typing the following command in the Terminal:
$defaults write com.apple.Finder AppleShowAllFiles YES
Then, either log out and log back in, or just give the Finder a few minutes to pick up the change. This seems cute at first (and some people may find it useful), but it can quickly become irritating, so you might find yourself preferring the Finder’s regular view instead. To reverse this setting, use the following command:
$defaults write com.apple.Finder AppleShowAllFiles NO
This command uses the defaults system, which is covered in more detail in Chapter 14.