2

This question already has an answer here:

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.

marked as duplicate by αғsнιη, muru, Charles Green, Avinash Raj, Sylvain Pineau Oct 30 '14 at 6:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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
5

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

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