The OS X Terminal is a very useful and powerful tool for troubleshooting Mac systems, and in doing so, one of the more common steps in getting a task done is to change directories to target files in it. The contemporary method of doing this is to use the "cd" (change directory) command and then specify a filesystem path; however, this can be a bit frustrating to deal with, especially if you are relatively new to the Terminal and are not too familiar with text-based filesystem browsing.
Given that Apple provides a fairly easy to use filesystem browser in OS X with the Finder, it has implemented options in both the Finder and the Terminal that allow you to use the Finder for quickly targeting folders in the Terminal without having to type full paths.
- Finder services
OS X services are contextually aware features where one application may provide options for handling data from another application, such as Apple's summarize service allowing you to select a body of text in practically any application and then providing a truncated version of it. Services are set up in the Keyboard Shortcuts section of the Keyboard preferences pane, and then are accessed either in the File menu or in the contextual menu by right-clicking. One service that Apple offers for the Finder is to open a new Terminal window or tab at the selected folder.
First ensure this service is active by checking it in the "Files and Folders" section of the Services list, and then go to the Finder and locate a folder you would like to open in the Terminal. Then right-click it and choose the "New Terminal at Folder" option that should now be available in the Services submenu. When this is done, a new Terminal window should open at the selected folder.
- Folder dragging
Services are great for establishing a starting folder in the Terminal, but often you may wish to specify other folder paths in the current Terminal session. If the target folder is visible in the Finder then you can drag it to the Window to input the full file path to it at the point of the cursor. This can be exceptionally convenient if you have deeply nested folders you need to access to copy or move files.
- Immediate directory switching
The folder-dragging feature can be used to switch directories to the target one by typing "cd" (change directory command) followed by a single space and then dragging your target folder to the Terminal before pressing Enter to execute the command; however, if you are using Mountain Lion then Apple has implemented a new approach to doing this. If you hold the Command key down when dragging a file or folder to the Terminal, then the Terminal will immediately change to the parent folder of the dragged file (or to the folder itself if a folder is dragged).
These enhancements in OS X should help Terminal-savvy users better navigate the filesystem, though for people who are very proficient at the command line, perhaps nothing comes close to an efficient use of the Bash shell's Tab-completion feature.