cd to a directory has hash (#) [duplicate]
By Daniel Rodriguez •
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.
12 Answers
Quote the directory name:
$ cd '#foo'Or escape it using a backslash:
$ cd \#foo
$ cd bar# #worksThe 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_commentsNow, you can cd to a directory start with # normally:
$ cuonglm at /tmp
$ cd #asd
$ cuonglm at /tmp/#asd
$ pwd
/tmp/#asd