The one thing that trips me up time and again when using the command line in Terminal or other terminal emulator is being able to navigate the directory structure and target files or folders. After struggling getting the correct file or folder path I’m usually greeted with No such file or directory reminding me that the command line doesn’t like spaces in file and folder paths.
With that in mind here are a few ways to enter file and folder paths on the command line.
I’m going to change the current directory to /Users/steve/Library/Application Support using the cd command.
The first method is to enclose the full path in single quotes…:
cd '/Users/steve/Library/Application Support'
…or double quotes:
cd "/Users/steve/Library/Application Support"
The second is to escape any space with a backslash \. The backslash should be placed immediately before each space:
cd /Users/steve/Library/Application\ Support
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:
cd ~/Library/Application\ Support
If we want to use single or double quotes, the opening quote must come after the ~/ shorthand:
cd ~/"Library/Application Support"
The one I tend to use most is to first type the command at the command line with a trailing space. Then locate the file or folder in the Finder and drag it to the open Terminal window:
The full path is copied at the Terminal window’s current cursor position:
Thank You! This is very helpful.
Fyi: This (“/”) is a forward slash. This (“\”) is a backslash. It goes from bottom to top.
@Ben
Ooops! Fixed.
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.
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.