How do I access folders that contain space in Terminal. (ie. My Folder)

A

AlexN

Guest
How do I access folders that contain space in Terminal. (ie. My Folder)

"cd My Folder" doesn't work.
 
Joined
Feb 6, 2005
Messages
1,551
Reaction score
102
Points
63
Location
Chicago
Your Mac's Specs
MacBook Pro M1 • iPhone 14 Pro • iPad Pro • iMac Retina 27"
You access the directory based on its path.

If you have a directory called "Music" in your home directory, you get there by typing "cd Music" if you're already in your home directory (which is where Terminal puts you by default)

You can also use "cd ~/Music" if you're somewhere other than your home directory.

If you're trying to do all this as the root user, you need to use the absolute path, e.g "cd /Users/username/Music"

If your issue is that you're trying to access a directory that has a space in its name, you tell the UNIX shell to avoid interpreting the space by using a backslash before the offending character. In your example, you would type "cd My\ Folder" (note the backslash before the space before the word "Folder".
 
Joined
Feb 9, 2005
Messages
2,340
Reaction score
82
Points
48
Location
DFW
Your Mac's Specs
MacBook Pro 13" | MacBook Pro 13" | Mac Mini 2GHz C2D
i have used:

cd "My Folder"

and it worked. You can give that a try.
 
Joined
Jul 22, 2003
Messages
6,999
Reaction score
187
Points
63
Location
Hamilton College
Your Mac's Specs
20" iMac C2D 2.16ghz, 13" MacBook 2.0ghz, 60gb iPod vid, 1gb nano
The initial directory is your home directory so unless the folder is in their you need to specify the path more

cd /Desktop/My Folder
 
Joined
Aug 17, 2005
Messages
39
Reaction score
0
Points
6
Always remember that the tab key is your friend and will autocomplete for you. e.g. typing "cd My" + hitting tab will complete the line for you as "cd My\ Folder/".
 
Joined
Mar 30, 2004
Messages
4,744
Reaction score
381
Points
83
Location
USA
Your Mac's Specs
12" Apple PowerBook G4 (1.5GHz)
Don't forget the easy way...
cd<space>+drag the folder icon from the Finder into the Terminal window.

Much better than trying to type "cd ~/folder/subfolder/subsubfolder/subsubsubfolder/sub...." without making a typo.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top