Working with File and Directory Names
Traditionally, Unix users tend to avoid spaces in file and directory names, sometimes inserting hyphens and underscores where spaces are implied, as follows:
textFile.txt text-file.txt text_file.txt
However, most Mac users tend to insert spaces into their file and directory names, and in a lot of cases, these names tend to be long and descriptive. While this practice is okay if you’re going to work in the GUI all the time, it creates a small hurdle to jump over when you’re working on the command line. To get around these spaces, you have two choices: escape them, or quote the file or directory name.
To escape a space on the command line, simply
insert a backslash (\) before the space or any
other special characters, such as a parenthesis. Because they have
meaning to the shell, special characters that must be escaped are:
* # ` " ' \ $ | & ? ; ~
( ) < >! ^. Here is an example of how to use a backslash to escape
a space character in a file or directory name:
cd ~/Documents/Editorial\ Reports
Or you can use quotation marks around the file or directory name that contains the space, as follows:
cd ~/Documents/"Editorial Reports"
There is one other way to get around this problem, but it involves using the Finder in combination with the Terminal application. To launch a Classic application such as Word 2001, which probably lives on the Mac OS 9 partition of your hard drive, you could enter the path as follows, using escape characters:
open -a /Volumes/Mac\ ...