Mac OS: About Folders, Directories, and Pathnames

Sometimes it is helpful to describe a file or folder by its pathname. This article discusses the relationship between folders, pathnames, and directories.
Cet article a été archivé et ne sera plus mis à jour par Apple.

The Mac OS Finder allows you to navigate a file system with easily recognizable file and folder icons. The Finder is all you need to know about the file system for daily usage of your Macintosh. However, you may occasionally need to perform an administrative task described in terms of directories and pathnames. Readers and writers of technical documents can locate a file or directory precisely and efficiently by using a pathname.

What is a directory?

A directory is a file that lists the names of items contained on a disk or other piece of storage media. The directory does not actually contain these items, but it does contain information that tells the operating system how to find the item on the disk. A directory can list different types of files, including other directories, meaning that the directory structure of a disk can be multi-tiered.

Expert users can view a text-only directory with tools such as the Terminal application (Figure 1).

Figure 1 Directory listings in a Terminal window

The top directory of a disk is called the root directory. Other directories branch from the root, which you could diagram like a family tree or tournament bracket. Each file on the computer is assigned to one directory, like a leaf on a branch. File systems structured like this are frequently described as hierarchical. When describing the position of one directory to another, you may use the terms subdirectory and parent directory. For example (Figure 1):
  • Documents is a subdirectory of the Home directory (~).
  • root (/) is the parent directory of the Users directory.

What is a folder?

A folder is the graphical representation of a directory. Together with the Finder (Figure 2), folders provide an easily understood way to see and manipulate a file system. Moving an item in or out of a folder in the Finder changes the underlying directory. The terms folder and directory are sometimes used interchangeably, when the distinction is not relevant.

Figure 2 Folders in the Finder Column View

Note: It is normal for the Finder to display fewer folders than there are directories listed in the Terminal. This enhances simplicity by hiding items which are only used by the operating system.

What is a pathname?

To find a file or folder, you follow a particular path. As in Figure 2, you might open the Mac OS X disk, then the Users folder, then the folder with your user name (or Home directory), and finally your Desktop folder. A pathname is simply a concise way to identify a folder by both its name and its location in the file system. This is important when files and folders have the same name and can only be differentiated by location. Mac OS X, for example, has four or more folders named "Fonts" that can only be identified by pathname.

Absolute pathname

An absolute pathname gives an exact location by including the name of every folder in the path from the root of the disk to the item being named. For example, the absolute pathname of the Desktop folder in Figure 2 would be:

Note that the root of the disk is represented simply by the first solidus, or "slash," symbol. Each subsequent solidus marks a division between the names of nested folders.

Relative pathname

A relative pathname is described from the current location. If you were the user mdh and you selected the Users folder (Figure 2), then the relative pathname for the Desktop folder would be:
Special abbreviations: the Home directory (~/) and root directory (/)

It is conventional to use the tilde (~) character to represent the Home directory. For example, you could note that each user can install personal fonts at ~/Library/Fonts/ in Mac OS X. The tilde may refer to Home directories stored on your computer or on a network server.

It conventional to represent the root directory with the first solidus (/) character in an absolute pathname.

Punctuation of pathnames: solidus (/) versus colon (:)

For Mac OS X and other UNIX or UNIX-like operating systems, it is conventional to use the solidus (/) character to mark the division of names. In earlier versions of Mac OS, it is conventional to use a colon. A Mac OS 9 pathname would look like:

System Folder: Preferences: Sherlock Prefs: Sherlock Defaults
Date de publication : Feb 19, 2012