Tesla's Optimus Robot Everything From Tesla AI Day Bella Hadid's Spray-on Dress Hasbro's Indiana Jones Toy 'Hocus Pocus 2' Review AirPods Pro 2 Discount Meal Delivery Services Vitamins for Flu Season
Want CNET to notify you of price drops and the latest stories?
No, thank you

Options for changing folders in the OS X Terminal

One common routine in the OS X Terminal is entering file paths to change directories among other options, and OS X provides several means for doing this.

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.

Open folder in a terminal within Finder
With the service enabled, you can open a folder in the Terminal using the contextual menu. Screenshot by Topher Kessler/CNET
  1. 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.
  2. Command-dragging folders to the OS X Terminal
    Dragging a folder to the Terminal window with the Command key held down will issue this command and change directories to the dragged folder (click for larger view). Screenshot by Topher Kessler/CNET
  3. 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.
  4. 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.

Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.