2

I plugged my external HD, then in a Terminal, I type

ls /Volumes/TOSHIBA\ EXT

This lists files and folders as expected, but then entering:

cd /Volumes/TOSHIBA\ EXT

throws the following message

-bash: cd: /Volumes/TOSHIBA\: No such file or directory

I can even reproduce this behavior with my own folders.

What is going on here? How do I change to a directory when it has spaces?

this is my environment context

uname -vsr
Darwin 17.5.0 Darwin Kernel Version 17.5.0: Mon Mar 5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64
  • 2
    Please edit your post with the output of the command ls -la /Volumes – Allan Apr 29 '18 at 17:09
  • 1
    Try dropping the backslash and just cd /Volumes/TOSHIBA see if that works. – ArchonOSX Apr 30 '18 at 0:12
  • 1
    Please add the output of ls -la /Volumes and ls -laB /Volumes by editing the question and pasting the result. Also, does cd /Volumes/TOS* work? – nohillside May 3 '18 at 15:23
5

Spaces in file names can be a hassle in the shell. Your best solution would be to both wrap the name in " characters and use the shell's built in completion to get the right name.

Type cd "/Volumes/TOSH then type a tab and the shell will complete the name with any spaces and non-standard characters included. If the tab completes the entire path then the shell will even insert a "/ at the end so you are ready to then hit return.

Note that standard bash completion will work on file paths and names for most shell commands, not just cd.

  • Hi, thx for the replay. Unfortunately, this didn't work for me. – user287257 May 3 '18 at 14:53
  • As mentioned by @patrix in a comment on the question, please add the output of ls -la /Volumes and ls -laB /Volumes. – Nimesh Neema May 3 '18 at 19:18
0

Guided by this response I found that GVM2 "Golang Version Manager" added CD function in my PATH, which somehow took precedence over the BASH CD.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .