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:
The full file/folder path is copied at the Terminal window’s current cursor position:
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.
Fyi: This (“/”) is a forward slash. This (“\”) is a backslash. It goes from bottom to top.
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.
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.