1

I want to cd to a path with spaces in the folder names, but it doesn't work. I want to navigate straight to a directory which has multiple levels of directories on the way, each with a lot of spaces. Please look at the following example:

Say I want to navigate to:

./Folder/Animal Pictures/Dog Pictures/Golden Retriever Pictures/Golden Retrievers Playing Ball

I tried:

cd ./Folder/"Animal Pictures"/"Dog Pictures"/"Golden Retriever Pictures"/"Golden Retrievers Playing Ball"

But I got the error:

cd: too many arguments

What should I do?

  • Your example looks fine syntax-wise – is this literally copied from the terminal (where you got the error message) or did you re-type it? – u1686_grawity Mar 01 '22 at 08:37
  • @user1686 - indeed, the quotes ought to work. I'd wondered if there were too many levels, but I've tested up to 5 deep, still works. The `./folder/` bothers me a bit. My answer below bypasses all the need for this, though, by simply dragging the required folder from Finder. This will make it apparent how terminal likes to see any particular path. – Tetsujin Mar 01 '22 at 09:30
  • Thanks a lot for the comments everyone! It wasn't copied from the terminal, I made up an example cuz the relevant folder names had a lot of personal info in it. I thought it was syntaxwise correct too, still no idea why it doesn't work. – hepcmb_codingnoob Mar 02 '22 at 14:23
  • Also I didn't know you could drag the folder into terminal, it's a great tip! Thanks :) – hepcmb_codingnoob Mar 02 '22 at 14:23

1 Answers1

1

You use a backslash to indicate the next character is part of the name & not a split where a new instruction starts.

cd ./Folder/Animal\ Pictures/Dog\ Pictures/Golden\ Retriever Pictures/Golden\ Retrievers\ Playing\ Ball

You can test this - or even use it to be much quicker than typing, by just typing cd then dragging the folder itself from Finder to Terminal. It will format it correctly for you.

Tetsujin
  • 47,296
  • 8
  • 108
  • 135
  • 1
    Ahh the backslash worked! When I first read about the backslash I just assumed it treats EVERYTHING that comes after it as a string, but I guess the regular slash kind of resets it? Anyways the folder drag is also a great idea. Thanks a lot! – hepcmb_codingnoob Mar 02 '22 at 14:22