Directory Files and Ordinary Files

Like a family tree, the tree representing the filesystem is usually pictured upside down, with its root at the top. Figures 4-2 and 4-3 show that the tree "grows" downward from the root, with paths connecting the root to each of the other files. At the end of each path is either an ordinary file or a directory file. Ordinary files, or simply files, appear at the ends of paths that cannot support other paths. Directory files, also referred to as directories or folders, are the points that other paths can branch off from. (Figures 4-2 and 4-3 show some empty directories.) When you refer to the tree, up is toward the root and down is away from the root. Directories directly connected by a path are called parents (closer to the root) and children (farther from the root). A pathname is a series of names that trace a path along branches from one file to another. More information about pathnames appears on page 78.

Figure 4-3. Directories and ordinary files


Every file has a filename. The maximum length of a filename varies with the type of filesystem; Mac OS X supports several types of filesystems. Although most of today's filesystems allow you to create files with names up to 255 characters long, some filesystems restrict you to shorter names. While you can use almost any character in a filename, you will avoid confusion if you choose characters from the following list:

  • Uppercase letters (AZ)

  • Lowercase letters (az)

  • Numbers (09)

  • Underscore (_)

  • Period (.)

  • Comma (,)

/ or root

The root directory is always named / (slash) and referred to by this single character. No other file can use this name or have a / in its name. However, in a pathname, which is a string of filenames including directory names, the slash separates filenames (page 78).

Caution: Copying files from HFS+ and HFSX filesystems can garble filenames

The Mac OS HFS+ and HFSX filesystems (page 86) support filenames using the Unicode (page 959) character set, in the UTF-8 (page 960) encoding. Filenames that use extended characters from Unicode may become garbled when you copy the files to other types of filesystems.

Like the children of one parent, no two files in the same directory can have the same name. (Parents give their children different names because it makes good sense, but Mac OS X requires it.) Files in different directories, like the children of different parents, can have the same name.

The filenames you choose should mean something. Too often a directory is filled with important files with such unhelpful names as hold1, wombat, and junk, not to mention foo and foobar. Such names are poor choices because they do not help you recall what you stored in a file. The following filenames conform to the suggested syntax and convey information about the contents of the file:

  • correspond

  • january

  • davis

  • reports

  • 2001

  • acct_payable

Filename length

When you share your files with users on other systems, you may need to make long filenames differ within the first few characters. Systems running DOS or older versions of Windows have an 8-character filename body length and a 3-character filename extension length limit. Some UNIX systems have a 14-character limit and older Macintosh systems have a 31-character limit. If you keep the filenames short, they are easy to type; later you can add extensions to them without exceeding the shorter limits imposed by some filesystems. The disadvantage of short filenames is that they are typically less descriptive than long filenames.

Long filenames enable you to assign descriptive names to files. To help you select among files without typing entire filenames, shells support filename completion. For more information about this feature, see the "Filename Completion" tip on page 43.

Case sensitivity

You can use uppercase and/or lowercase letters within filenames, but be careful: Some filesystems are case sensitive. For example, the UFS filesystem is case sensitive, so files named JANUARY, January, and january represent three distinct files. The FAT filesystem (used mostly for removable media) is not case sensitive, so those three filenames represent the same file. The HFS+ filesystem, which is the default OS X filesystem, is case preserving but not case sensitive. Case preserving means that the filesystem remembers which capitalization you used when you created a file and displays the filename with that capitalization, but it accepts any capitalization to refer to the file. Under HFS+, the three example filenames refer to the same file. The HFS+ Extended (HFSX) filesystem is case sensitive and is fully supported only under Mac OS X Server. Under HFSX, the three example filenames refer to three different files.

Caution: Do not use SPACEs within filenames

Although you can use SPACEs within filenames, it is a poor idea to do so when you are working on the command line. Because a SPACE is a special character, you must quote it on a command line. Quoting a character on a command line can be difficult for a novice user and cumbersome for an experienced user. Furthermore, many shell scripts do not properly handle filenames with SPACEs in them. Use periods or underscores instead of SPACEs: joe.02.04.26, new_stuff.

Filename Extensions

A filename extension is the part of the filename following an embedded period. In the filenames listed in Table 4-1, filename extensions help describe the contents of the file. Some programs, such as the C programming language compiler, depend on specific filename extensions; in most cases, however, filename extensions are optional. Some applications use filename extensions to identify files, but many use type codes and creator codes (page 96). Use extensions freely to make filenames easy to understand. If you like, you can use several periods within the same filenamefor example, notes.4.10.01 or files.tar.gz.

Table 4-1. Filename extensions


Meaning of extension


An executable file

An executable file or a directory that contains an application bundle (an application program and its support files)


A C programming language source file


A disk image file that can be mounted the way you would mount a CD-ROM


An object code file


A package file for use with the Apple Installer application


A text file


A file compressed with bzip2 (page 54); view with bzcat or decompress with bunzip2


A file compressed with gzip (page 55); view with zcat or decompress with gunzip


A file meant to be viewed using a Web browser, such as Safari


A PDF file; display with the Preview application or use open (page 42)

A PostScript file; display with the Preview application or use open (page 42)


A tar (page 56) archive of files compressed with compress (page 55)

memo.tbz2 or memo.tar.bz2

A tar archive of files compressed with bzip2 (page 54)

memo.tgz or memo.tar.gz

A tar archive of files compressed with gzip (page 55)


A file compressed with compress; use uncompress (or gunzip, page 55) to decompress

photo.gif, photo.jpg, photo.jpeg, photo.bmp, photo.tif, or photo.tiff

A file containing graphical information, such as a picture

Invisible Filenames

A filename that begins with a period is called an invisible filename (or an invisible file or sometimes a hidden file) because ls and the Mac OS X GUI do not normally display it. The command ls a displays all filenames, even invisible ones. Names of startup files (page 77) usually begin with a period so that they are invisible and do not clutter a directory listing. The .plan file (page 61) is also invisible. Two special invisible entriesa single and double period (. and ..)appear in every directory (page 82).

You can also hide files from the OS X GUI by setting the file's invisible flag (page 95) using SetFile (page 834). The OS X GUI does not normally display files that have this flag set, although ls does. Under Mac OS X 10.3 and earlier, files listed in the file named .hidden in the root directory are not displayed by the GUI. Files named .hidden in other directories are ignored. The .hidden file is not used under Mac OS 10.4 and later.

The Working Directory


While you are logged in on a character-based interface to a Mac OS X system, you are always associated with a directory. The directory you are associated with or are working in is called the working directory or current directory. Sometimes this association is referred to in a physical sense: "You are in (or working in) the max directory." The pwd (print working directory) utility displays the pathname of the working directory.

Your Home Directory

When you first log in on a Mac OS X system or start a Terminal window, your working directory is your home directory. To display the pathname of your home directory, use pwd just after you log in (Figure 4-4).

Figure 4-4. Logging in and displaying the pathname of your home directory
login: zach Password: Last login: Wed Oct 20 11:14:21 from bravo Welcome to Darwin! $ pwd /Users/zach 

When used without any arguments, the ls utility displays a list of the files in the working directory. Because your home directory is the only working directory you have used so far, ls has always displayed a list of files in your home directory. (All the files you have created up to this point were created in your home directory.)

Startup Files

Also called configuration files or preference files

Startup files, which appear in your home directory, give the shell and other programs information about you and your preferences. Mac OS and application documentation refer to startup files as configuration files or preference files. Frequently one of these files tells the shell what kind of terminal you are using (page 913) and executes the stty (set terminal) utility to establish the erase (page 25) and line kill (page 25) keys.

Either you or the system administrator can put a shell startup file containing shell commands in your home directory. The shell executes the commands in this file each time you log in. Because startup files have invisible filenames, you must use the ls a command to see whether one is present in your home directory. See pages 259 and 340 for more information about startup files.

Many Mac OS X applications store startup files in the Library and Library/Preferences subdirectories of your home directory, which are created when an account is set up. Most of these files do not have invisible filenames.

A Practical Guide to UNIX[r] for Mac OS[r] X Users
A Practical Guide to UNIX for Mac OS X Users
ISBN: 0131863339
EAN: 2147483647
Year: 2005
Pages: 234

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: