Chapter 3. File Management

Chapter 2 introduced the Unix filesystem. This chapter explains how to name, edit, copy, move, and find files.

File and Directory Names

As Chapter 2 explained, both files and directories are identified by their names. A directory is really just a special kind of file, so the rules for naming directories are the same as the rules for naming files.

Filenames may contain any character except /, which is reserved as the separator between files and directories in a pathname. Filenames are usually made of upper- and lowercase letters, numbers, “.” (dots), and “_” (underscores). Other characters (including spaces) are legal in a filename, but they can be hard to use because the shell gives them special meanings. However, spaces are a standard part of Macintosh file and folder names, so while we recommend using only letters, numbers, dots, and underscore characters for filenames, the reality is that you will have to work with spaces in file and directory names. The Finder, by contrast, dislikes colons (which older versions of Mac OS used as a directory separator, just as Unix uses the slash). If you display a file called test:me in the Finder, the name is shown as test/me instead. (The reverse is also true: if you create a file in the Finder whose name contains a slash, it will appear as a colon in the Terminal.)

If you have a file with spaces in its name, the shell will be confused if you type its name on the command line. That’s because the shell breaks ...

Get Learning Unix for Mac OS X, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.