4

I have a folder named abcd\fff\ggg\ddd

How do I cd into it?

  • How on earth did you manage to get a folder with slashes in the name?! Most operating systems go well out of their way to prevent that from ever, ever happening. Also, what operating system are you using? It would make answering your question easier ;) – nhinkle Aug 18 '10 at 22:32
  • im using ubuntu – Or W Aug 18 '10 at 23:26
  • @nhinkle: I've noticed the opposite: Most operating systems allow everything that is not forbidden for a good reason. Any well-written Unix program — including Nautilus, GNOME's graphical file browser — will let you enter anything as file name (except a slash /). – grawity Aug 19 '10 at 20:57
  • @nhinkle: (Well, okay, Nautilus won't let you enter newline characters. But it's as simple as mkdir "foo[Enter]bar" in the shell.) – grawity Aug 19 '10 at 20:58
  • Ahhh, ok. On Windows, we use \ for directories, not / like on unix, so \ is therefore a prohibited character. That makes more sense now (and hence my question about the OS ;) ) – nhinkle Aug 20 '10 at 9:57
6

You have to escape the backslash character in order for it to work:

cd abcd\\fff\\ggg\\ddd/

Escaping means prefixing the backslash (also have to do this if the directory contains a space) with, funnily enough, a backslash. Linux interprets a single backslash as the escape character, allowing you to access directories and files containing spaces, backslashes, and other special characters.

That is best practice; it is a good idea to get in the habit of understanding how and when to use the escape character if you're going to be using Linux command line. The other answer provided:

cd 'abcd\fff\ggg\ddd'

will also work. I provided mine as a more complete and 'correct' answer, since understanding the concept of escape characters is essential to proper CLI interaction.

4
cd 'abcd\fff\ggg\ddd'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.