Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

In terminal I want to change a directory to something with a # sign in it. For example #filename.chat and can't seem to remember how to do this. From the command line I think it is suppose to be cd /filename.chat/ but doesn't seem to work.

share|improve this question
add comment

2 Answers 2

Actually the best way to do this is to use the \ escape character. The method that @Shauna suggests will work in this case but has limitations. For example if the filename has quotes in it what do you do? this?:

cd "some """Movie Title"""" 

No, that would be silly. You would do this:

cd some\ \"Movie\ Title\"

The next character after the escape \ is not interpretted by the shell. This is what we want.

There are three methods of escaping character in bash.

  • Double quotes

Least powerful method. Preserves literal value except for dollar sign, backticks, and backslash.(tldp.org)

  • Single quotes

Most powerful. Hides all special characters.

  • Backslash

Similar to single quotes, but only hides one character at a time.

A good resource for this is TLDP

share|improve this answer
1  
I wouldn't say @Shauna 's method is incorrect, but it's important to be aware of the limits of the method. Thanks for pointing it out. –  not__p Mar 7 '13 at 22:08
1  
@Jason I edited my post –  shakabra Mar 7 '13 at 22:23
add comment

Just put quotes around it, like this:

cd "#filename.chat"

If you lead with a /, then it's going to look for the file or folder in the root directory (just fyi).

share|improve this answer
2  
Alternatively escape the # by writing \#filename.chat –  teppic Mar 7 '13 at 21:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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