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?



2 Answers 2


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

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

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