3

Well, I have few directories have name contains hashes (#, eg: #abczxy). Now I can't to execute this cd #foo it will redirect me back to the root directory equal with this command cd

The question is, is this possible to do that or is there any tricks allow me do that?

Thanks.

terdon
  • 98,183
  • 15
  • 197
  • 293
Toan Nguyen
  • 392
  • 1
  • 2
  • 14
  • 1
    possible duplicate of [How do I change directory to a folder with special characters?](http://askubuntu.com/questions/101587/how-do-i-change-directory-to-a-folder-with-special-characters) And also duplicate of [Using cd command to navigate directories in Ubuntu which have special characters](http://askubuntu.com/questions/453770/using-cd-command-to-navigate-directories-in-ubuntu-which-have-special-characters?lq=1) – αғsнιη Oct 29 '14 at 18:10

2 Answers2

7

Quote the directory name:

$ cd '#foo'

Or escape it using a backslash:

$ cd \#foo
$ cd bar#  #works

The second one works since a comment at the end of the line must have whitespace before #.

Or give the full path:

$ cd ./#foo
terdon
  • 98,183
  • 15
  • 197
  • 293
muru
  • 193,181
  • 53
  • 473
  • 722
4

In addition to @muru's answer, you can disable bash interactive_comments option:

shopt -u interactive_comments

Now, you can cd to a directory start with # normally:

$ cuonglm at /tmp
$ cd #asd
$ cuonglm at /tmp/#asd
$ pwd
/tmp/#asd
cuonglm
  • 2,435
  • 16
  • 18