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
  • 100,812

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
  • 100,812
muru
  • 197,895
  • 55
  • 485
  • 740
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,455