Chapter  3

The Mac OS X File System

In this chapter, we are going to step back and take a tour of Mac OS X’s file system to discover what items exist in what folders and why (and also what you can but shouldn’t change, and why). We’ll the following cover in depth:

  • The overall file structure of Mac OS X
  • Your personal home folder and its contents
  • The top-level folders, including the System folder, Library folder, and Application folder
  • Other common folders
  • Hidden folders

The Overall File Structure of Mac OS X

Moving around the file system in Mac OS X is a bit like moving around a city on a subway. You start at one central station and choose a location to head toward. Once you get to the next station you may transfer trains and head to another station. You continue along your path, switching trains as needed, until you either reach your destination or reach the end of the line. In Mac OS X all local paths begin at the root of your primary hard drive (the one you boot Mac OS X from). From there a series of pathsmove downward, each with its own purpose. A basic map (like a subway map) outlining the paths of file system is shown in Figure 3–1.

Image

Figure 3–1. A simplified view of Mac OS X’s default file system

NOTE: Figure 3–1 describes roughly what is visible by default from the Finder. As you will see later in the chapter, there are a number of paths normally hidden from the Finder.

The file system is devised so that certain items belong in certain folders. For example, most of your applications go in an Applications folder, and most of your documents created by these applications go in the Documents folder within your home folder.

It’s common to use path to describe where something is located in the file system. A path consists of folder names separated by forward slashes (/), which indicate that one folder contains another. A path beginning at the root, or top level, of a file system will actually begin with a /. A path beginning in your home directory will begin with a tilde (~). For example, the path to my Documents folder in my computer folder could be written either as /Users/scott/Documents or ~/Documents.

NOTE: The actual name of your home folder is the account name (or short name) chosen when you set up an account in Lion. When I set up my account, I chose “Scott Meyers” as my full name, and “scott” as my account name, so my home folder is named scott.

NOTE: All these slashes and tildes may seem arbitrary at the moment, and it’s possible that you will never even have to type in a / or ~ to get where you need to go on your computer. The path notation you’re learning here, however, is necessary to access and utilize a lot of the features hidden beneath the surface of Mac OS X.

The Users Folder and Your Home

The Users folder, located in the root (top level) of the file system in every Mac OS X installation, is where each user’s personal folder resides. This personal folder is usually referred to as the user’s home folder (or just home). Inside the Users folder will be a home folder for each of the system’s users (named after the short name chosen when the account was created) and a Shared folder. The Shared folder is a place where files that are shared among all users may be kept. Your home directory is where you generally keep all of your documents, and where all of your personal settings are stored.

Your home folder, by default, starts out with ten subfolders: Applications, Desktop, Documents, Downloads, Library, Movies, Music, Pictures, Public, and Sites. Each of these folders has a specific purpose, as explained in Table 3–1.

NOTE: Beginning in Lion, user Library folders are hidden. There are some reasonable justifications for this; however, we feel this is still an important folder to discuss, so we are still going to discuss this as if it were still visible.

Image

Image

These default folders cover most of you personal folder needs (though subfolders are common in each of these). Occasionally you may want to add another folder for a specific need, and that’s fine; this is, after all, your home.

The Applications Folder

The Applications folders, as you may have guessed, is the recommended folder for installing and keeping applications. Most users have two primary Applications folders of significance: the main /Applications folder, where applications available to all users are located; and ~/Applications, where applications available only to a specific user are kept. (A third /Developer/Applications folder is created if you install the Xcode tools; this is where development applications may be stored.) Keeping all your applications in these folders makes things fairly easy to find and manage. If, however, you find that you have many applications and this folder starts to get cluttered, it’s common to create your own subfolders to organize types of applications. For example, you may create /Applications/Games for any games you install or /Applications/Graphics for any graphics apps you install. This sort of organization makes it easy to find what you are looking for.

NOTE: With the introduction of Launchpad, I find I rarely move any application into subfolders in the Applications folders; rather, I organize my applications into groups within Launchpad for quick and easy access.

TIP: You may want to drag any critical or frequently used applications on to the Dock so that they will always be a click away.

CAUTION: Some applications don’t like to be moved from where they are installed. For the most part, any moved application will function just fine; the problem is that sometimes, when it comes time to update your application, the update utility expects the original application to be in a specific location. This is especially true of Apple’s default applications, which are frequently updated with the Software Update utility. If you do move an application into a subfolder and something strange happens when you try to update it, you can usually move the application back to its original location and redo the update with no harm—it’s just a bit inconvenient. As a general rule, if an installer installs the application, it’s best to leave it where it installs (though often installers have an option to install in subfolders). If you install an application manually by just dragging it into the Applications folder (as you can do with many apps), then it’s probably safe to put it wherever you want.

The Library Folders

One thing you may notice about the file system is that there are multiple Library folders. This is by design, and while there are many similarities between the contents of the Library folders, they are scoped differently.

NOTE: There are actually four Library domains, though generally you only see three Library folders. Some applications can contain their own application-specific Library folder to contain plug-ins or other information that only they use.

The Library folders each contain the necessary support items for the applications on your system, as well as key system items. These include things like preference settings, cache items, scripts, and screen savers. In practice you almost never need to fuss with the contents of any Library folder; however, there are times when it may benefit you to do so (especially the Library folder in your home directory). That said, for each Library folder there are certain rules. We’ll look at each of the three primary Library folders in general first, and then we’ll explore common subitems contained in Library folders in general.

The Library and System Library Folders

The primary Library folder (/Library) has a global scope, as does the Library folder contained in the System folder (/System/Library). That is, their contents support every aspect of the system. Specifically, the System Library folder contains items necessary for the system to operate, and the primary Library folder contains the items necessary for most applications, third-party hardware, and other items that affect every user on the system.

As a general rule, the System Library is sacred. Only necessary system-level items should be installed there, and only system-level events should affect them. As such there is almost no reason for you (or me) to touch anything in there unless you are 100 percent sure you know exactly what you are doing and that doing it here is the only way to solve your problem. Changing anything here can cause very bad things to happen (or even worse . . . cause nothing at all to happen . . . ever).

On the other hand, there are times where it may benefit you to make a few changes to items in the main Library folder. This could be anything from installing a screen saver that you want to make available to all users of your computer to uninstalling some old items left over from an old application or hardware device. That said, you should still be 100 percent certain of what you are doing before you do it. While errors you make here might not render your system unusable, they could certainly make it less usable.

CAUTION: Though sometimes you may want to clean out old, unnecessary files that tend to build up in your Library folder, make sure that these items are no longer being used before you remove them. Sometimes an item installed by one item is used by another item as well (this is especially true with certain common frameworks and components). Often it’s better to err on the side of keeping an unnecessary item rather then accidentally deleting a necessary one.

The Personal Library Folder

The Library folder inside your home directory (~/Library) is your own personal Library folder. This is where settings that affect individual users are kept. This includes your personal system and application preferences, your mail settings (and actual mail), your Safari bookmarks, your iCal data, and much more. This Library folder is the preferred one for adding personal items such as screen savers, desktop backgrounds, and add-on scripts. This Library folder also is in most need of an occasional cleaning; however, all the cautions mentioned previously still apply.

TIP: As mentioned earlier, in Lion user Library folders are hidden; as such, they will not by default show up in the Finder. In Chapter 2 you learned about the Finder’s Go to Folder… command (Go > Go to Finder… from the Finder’s menu), where you can enter ~/Library to go to you user Library folder. An easier way to access your Library folder is directly from the Finder’s Go menu. If you hold the Option key down when you select the Go menu, Go > Library will appear as one of the selectable options.

Common Library Items

Each of the Library folders tend to share a number of subfolders that typically contain the same type of items. Some of the Library folders also contain unique subfolders that have special significance. Table 3–2 points out a few common Library subfolders and explains their purpose.

Image

Image

Image

Image

Image

Image

While there are other folders in your various Library folders (and often third-party applications will install their own), that covers many of the default ones. We’d just like to add one more caution that, as a rule of thumb, if you are unsure of what an item in one of your Library folders is, just leave it alone.

Other Common Folders

We’ve covered most of the default folders you’ll interact with in Lion, but there are some other common folders you may encounter as well. One of the most common is the /Developer folder, which is present if you install the Xcode tools during or after your Mac OS X installation. Contained in this folder are all the developer applications, documentation, and other items necessary to develop your own Mac OS X applications.

Another common folder that may present itself is the /opt folder. This folder is used by MacPorts (which we will talk about later in the book).

Hidden Folders

The folders we have talked about are really only a small subset of folders actually contained in Mac OS X. A majority of folders and contents are actually hidden from the Finder. These hidden files are mostly the UNIX parts of Mac OS X; this is largely referred to as the Darwin subsystem of OS X. Later, in Chapters 23 and 24, we will discuss Darwin and the UNIX underbelly of Mac OS X in greater depth.

If you are curious as to these hidden files, the following AppleScript can toggle the visibility of hidden Finder items:

tell application "Finder" to quit
try
        do shell script "defaults read com.apple.finder AppleShowAllFiles"
        set OnOff to result
on error
        set OnOff to "0"
end try

if OnOff = "0" then
         set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles 1"
else
         set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles 0"
endif
do shell script OnOffCommand
delay 1
tell application "Finder" to launch

To run this script, open the AppleScript Editor (found in the Utilities folder in Launchpad), type the script into the editor, and then click the Run button. Then have a look in the Finder and relish all the other folders and items that appear. Run the script again to rehide the hidden items. Feel free to create a Scripts folder in your ~/Library/ folder and save this little file there under “Toggle Hidden” or some such name so it will be available to you later.

NOTE: Most hidden files are there for a purpose, and are likewise hidden for a purpose. Usually this purpose is to protect the files from accidental disturbance by casual users. It’s generally best to leave hidden files alone, at least until you learn what they do and how to work with them properly (some of which will be covered in this book).

Summary

Now that you’ve had a glimpse of how everything is organized on your computer, and you know how to move around it, we’re going to take a brief sidetrack in the next chapter to point out a few of the unique features in Mac OS X, including the new Mission Control app.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset