39

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
Seth
  • 57,282
  • 43
  • 144
  • 200
webdev
  • 519
  • 2
  • 5
  • 10

2 Answers2

45

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

Avinash Raj
  • 77,204
  • 56
  • 214
  • 254
  • 1
    or after going to `/opt`, type `cd Sub` and then press `Tab` to autocomplete. – Web-E Jan 01 '14 at 04:50
  • Can you please explain to me why you need to use the double quotes? Is this for all directories that have spaces? Or for the directories marked in blue in the Terminal window? – webdev Jan 01 '14 at 04:50
  • no,its for the directory which contains spaces on their names. – Avinash Raj Jan 01 '14 at 04:51
  • Tried the tab for autocomplete, didn't do anything? - NVM, my mistake didn't use the caps on S. :/ – webdev Jan 01 '14 at 04:51
  • Thanks for all the help and information guys, appreciate it! – webdev Jan 01 '14 at 04:56
  • that worked for me. typing part of the name and pressing TAB completed the path with the backslaches. thkns – rodrigorf May 29 '18 at 17:31
3

If there are spaces in the name ,then just use a backslash('\') and then the space(' ') ,for e.g " os program " so in this there are three spaces so use three backslashes, so the command will be

cd \ os\ program\ 

so for each space in the name use a backslash and then the space, another example "os program" ,have two continuous space ,so command is

cd os\ \ program
Elder Geek
  • 35,476
  • 25
  • 95
  • 181
  • 2
    This looks exactly like the 2nd part of Avinash Raj answer. While it's factual, I'm not sure it needs repetition. – Elder Geek Mar 26 '15 at 19:12