|
Filenames and Paths in Mac OS X |
|
|
|
|
Written by Michael Salsbury
|
|
Wednesday, 23 May 2007 |
|
Since I am our sole Mac Administrator where I work, and our company produces and supports Mac software in addition to using a small number internally for graphic work, I'm often asked questions about Macintosh filenames and path names in OS X. What follows is what I've learned and gleaned during my administrative efforts and support activities, and I suspect is in no way a comprehensive discussion of file and path names on Mac OS X. However, it should answer most of the more common questions I've received over the years.
If the file is located on the disk OS X boots from, you should start the path name with a simple slash "/". For example, the path to the Terminal application would be specified as:
/Applications/Utilities/Terminal.app If the file is on a different disk, however, the syntax is a bit different. All the disks attached to your Mac are represented with virtual directories under the "/Volumes" directory. So if you had a file named "information.txt" which resides in a folder called "Data" on a disk drive called "Workdisk" you would specify the path as:
/Volumes/Workdisk/Data/information.txt If you want to specify a file that's on a mounted network volume, it's a little trickier because you need to know the name the Mac used to mount the disk in the "Volumes" directory. To do this, I would first execute the command:
ls /Volumes This will generate a result something like the following:
Macintosh HD Storage Workdisk Let's assume that the "Storage" volume is a shared directory on a Windows server that we've already connected to. Let's also assume that the file we're going to access from the command line is named "confidential.rtf" and that it's inside the directory "SecureDocs" which is itself inside a directory called "MacFiles1" on the Windows server. Our path in this case would look like this:
/Volumes/Storage/MacFiles1/SecureDocs/confidential.rtf There are a couple of "gotchas" here that I haven't mentioned, intentionally, to keep the examples straightforward up to this point. Let's now have a look at some of those little gotchas, because the odds are that you're going to see them pretty soon in your use of the OS X command line.
One of the first gotchas I ran into is the fact that you can use spaces in file and folder names on OS X, but that OS X's UNIX command line doesn't handle spaces in the same way that Windows XP and Windows Vista do. Windows XP, for example, is perfectly happy with being given a path like this on the command line:
C:\Program Files\Apple\QuickTime Pro\sample.mov XP will, at least in most cases, figure out what you mean. OS X, however, will treat the spaces in the command line as if they are part of the syntax of the command. For example, if you were to enter the path:
/Applications/QuickTime Tools/Some file.txt OS X is going to think your path name is actually several parts:
/Applications/QuickTime Tools/Some file.txt And it's going to at the very least generate an error, and in a worst case perform actions on the wrong files and folders. If you need to specify a path with spaces in it on the OS X command line, you need to "help" OS X understand that the spaces are a part of the path. There are two ways to do this, and there are circumstances where one may work better than the other (which you'll have to figure out through experimentation).
The first and simplest option is to simply put quotes around the path. Referring back to the previous example path, that would look something like this:
"/Applications/QuickTime Tools/Some file.txt" The double-quotes help OS X understand that the entire string between the two quotation marks is a single entity. As I mentioned, there are circumstances where this is your best option. There are others, such as in scripting, where you may find that for some reason it simply doesn't work as expected. In that case, you'll want to use the alternative method.
The alternative is to place a backslash "\" in front of each space. Referring back to our previous example, that would look like this:
/Applications/QuickTime\ Tools/Some\ file.txt In this case, the backslashes tell OS X to treat the following space as a part of the current string it's working with. This same technique can be useful if your filename contains other characters that could potentially confuse the command line, such as the apostrophe or single quote ('), the quotation mark or double-quote ("), or others. If you enter a path name that OS X doesn't like, you'll very likely get an error message or unexpected result. That will often be your clue to check the characters in the path name.
.com
|
|
Last Updated ( Thursday, 21 June 2007 )
|