File and Folder Paths in OS X Terminal

Steve June 2 Mac OS X , , with 5 and 0
Home/Mac OS X/File and Folder Paths in OS X Terminal

On the few occasions I use Terminal in OS X the biggest problem I seem to have is being able to navigate the directory hierarchy and access files or folders. After struggling with getting the correct file/folder path I’m usually greeted with No such file or directory reminding me that Terminal doesn’t like spaces in file/folder paths.

With that in mind here are a few ways to enter file/folder paths in Terminal.

For these examples I’m going to change the current directory from /Users/steve/Documents to /Users/steve/Library/Application Support using the cd command.

The first method is to enclose the file/folder path in single quotes…:

 
Steves-iMac-5K-27:Documents steve$ cd '/Users/steve/Library/Application Support'
Steves-iMac-5K-27:Application Support steve$
 

 

…or double quotes:

 
Steves-iMac-5K-27:Documents steve$ cd "/Users/steve/Library/Application Support"
Steves-iMac-5K-27:Application Support steve$
 

 

 

The second is to escape any space with a backslash (\). The backslash should be placed immediately before each space:

 
Steves-iMac-5K-27:Documents steve$ cd /Users/steve/Library/Application\ Support
Steves-iMac-5K-27:Application Support steve$
 

 

 

If the file or folder exists in the current user’s home folder we can use ~/ as shorthand to denote the user’s home folder:

 
Steves-iMac-5K-27:Documents steve$ cd ~/Library/Application\ Support
Steves-iMac-5K-27:Application Support steve$
 

 

 

If we want to use quotes, the opening quote must come after the ~/ shorthand:

 
Steves-iMac-5K-27:Documents steve$ cd ~/'Library/Application Support'
Steves-iMac-5K-27:Application Support steve$
 

 

 

The one I use most though, because it is perhaps the easiest, is to locate the file or folder in the Finder and drag it to an open Terminal window:

Dragging an item from the Finder to a Terminal window

Dragging an item from the Finder to a Terminal window

 

 

The full file/folder path is copied at the Terminal window’s current cursor position:

Terminal window showing the full path of the Finder item

Terminal window showing the full path of the Finder item

 

 

About the Author

A native Brit exiled in Japan, Steve spends too much of his time struggling with the Japanese language, dreaming of Fish & Chips and writing the occasional blog post he hopes others will find helpful.

5 Responses

4 Comments

  • Ben Hudelson
    on November 28th, 2013 at 07:07
    Reply

    Fyi: This (“/”) is a forward slash. This (“\”) is a backslash. It goes from bottom to top.

    • Author
      Steve
      on November 28th, 2013 at 14:47
      Reply

      @Ben

      Ooops! Fixed.

  • Khushal B
    on June 29th, 2012 at 23:24
    Reply

    I am trying to access a folder on my external drive. The name of the folder is “Story Telling”

    I am not able to access this folder using Terminal. Although this folder very much exists.
    It says no such file or directory.

    Now there another folder called “Story” without the space in between and when I try to open this directory I can open it.

    Only when there is a particular folder with the ‘White space” in between i am not able to access it.
    Would appreciate your help.

    • Author
      Steve
      on June 30th, 2012 at 13:20
      Reply

      Khushal B

      If none of the methods I’ve outlined in this post work for you, try this:

      Select the Story Telling folder in the Finder. Ctrl-click and select Services > New Terminal at Folder from the resulting menu. This should open a Terminal window at the Story Telling folder location.

      Regards, Steve.

1 Pingback

Add comment

©Tech Otaku 2009 - 2017