There’s a folder called My Documents. You can see it in the file manager, and you can see it in ls. You try to open it from the terminal:
$ cd My Documents
bash: cd: too many arguments
Or you try to list it and get something even stranger, two errors for two things you never typed:
$ ls My Documents
ls: cannot access 'My': No such file or directory
ls: cannot access 'Documents': No such file or directory
The folder exists. The command is spelled correctly. What’s going wrong is that the shell never passed My Documents to the command as one name. It passed two.
What’s actually happening
Before a command runs, the shell reads the line you typed and splits it into words. The separator is whitespace. The first word is the command, and every word after it becomes a separate argument. That’s how ls -l /tmp knows that -l and /tmp are two different things.
A space inside a filename is, to the shell, exactly the same as a space between arguments. So cd My Documents isn’t “change to the directory My Documents”. It’s “run cd with two arguments: My and Documents”. cd only accepts one, so it complains about too many. ls accepts many, so it quietly tries to list a file called My and a file called Documents, finds neither, and reports both.
The commands are behaving correctly. The problem is that the splitting happened before they ever saw your input. The fix is to tell the shell not to split.
The fix, step by step
1. Wrap the name in quotes. Either kind works, and everything inside is treated as one word:
$ cd "My Documents"
$ ls 'My Documents'
notes.txt
2. Or escape each space with a backslash. This tells the shell “this particular space is part of the name”:
$ ls My\ Documents
notes.txt
3. Or let tab completion do it for you. Type cd My and press Tab. The shell completes the name and inserts the backslash for you. It’s the least error-prone way to type a path interactively.
4. Inside scripts, quote every variable that holds a path. This is where the problem hides longest. A variable that contains a space gets split exactly the same way as typed text:
d="My Documents"
ls $d # splits into two words, fails
ls "$d" # one word, works
The habit is to write "$d" with double quotes every time, not just when you know the value has a space. Paths you control today will gain a space tomorrow.
Two mistakes worth knowing about ahead of time
Running a delete command without quotes. With ls, splitting gives you an error. With rm, it can delete the wrong thing. Suppose a folder holds a file called my file.txt and also a short file named my:
$ ls
my my file.txt
$ rm my file.txt
rm: cannot remove 'file.txt': No such file or directory
$ ls
my file.txt
The shell treated it as two names, my and file.txt. It couldn’t find file.txt, but it did find my, and deleted it, while my file.txt stayed untouched. The error looked harmless, but a different file was gone. Before you delete anything with a space in its name, quote it, and if you’re unsure, run ls with the same arguments first to see what it matches.
Looping over filenames with $(ls ...). This is the loop version of the same bug:
$ for f in $(ls *.txt); do echo "[$f]"; done
[a]
[b.txt]
[c.txt]
The file a b.txt was split into a and b.txt. Let the shell expand the pattern itself instead, which keeps each filename intact:
$ for f in *.txt; do echo "[$f]"; done
[a b.txt]
[c.txt]
Quotes: single or double?
Both group words together, but they differ on variables. Double quotes still expand $variables, and single quotes treat everything literally:
$ v=World
$ echo "Hello $v"
Hello World
$ echo 'Hello $v'
Hello $v
For a plain filename, either works. For a path built from a variable, use double quotes so the variable is expanded and the result still stays in one piece.
These examples use bash, which is also what you get on Linux, in WSL, and in Git Bash on Windows. On macOS, zsh behaves the same way for everything shown here.
A habit that prevents the confusion entirely
Treat quotes as part of how you refer to any path, not as an emergency fix. Quote names when you type them, quote variables in every script, and when a command says “too many arguments” or “cannot access” a name you can clearly see, the first thing to check is whether a space in the name is being read as a separator. A pair of quotes costs nothing, and the one time you skip them is the time that a space-filled filename turns up.