Ubuntu – How to navigate to folders with spaces in their names? I get “no such file or directory” when I try

command line

I'm completely new and lost in Ubuntu 12.04, I'm having trouble navigating to my Sublime folder which I know is in my /opt folder. Yet I've tried to no avail to navigate into it via Terminal window. The directory is colored in blue, no idea what this means…but I am able to access the folder using the GUI explorer…?

k@k-Ubuntu:~$ cd /opt
k@k-Ubuntu:/opt$ ls
Sublime Text 2
k@k-Ubuntu:/opt$ cd Sublime Text 2
bash: cd: Sublime: No such file or directory
k@k-Ubuntu:/opt$ cd /Sublime Text 2
bash: cd: /Sublime: No such file or directory

Best Answer

Go inside the /opt directory via terminal and then run below command,

k@k-Ubuntu:~$ cd /opt
k@k-Ubuntu:/opt$ cd "Sublime Text 2"

As the folder you want to connect has spaces in the name, you must surround the name with quotes in order for the Shell to read it correctly (as one name). In other case it will read only the Sublime and this doesn’t exist.

Another way to avoid this issue, is to use Tab Completion. This is a feature that will help you to auto-fill weird names and/or long names. Read here about Tab Completion and learn it. It is very useful(in Ubuntu is pre-installed).

A third way for names with spaces is the backslash \ . Above command with quotes could be

cd Sublime\ Text\ 2/

the backslash followed by a space explicitly denotes a space.

A suggestion could be: Do not create folders in Linux with space in name. Prefer something like Sublime-Text-2 or Sublime_Text_2