5 Answers
5

That error is happening because the ! (bang) is a shortcut that allows you re-run a command from your history. Ex: This command re-runs command #1504 from my history.

$ !1504

To avoid that issue, try encapsulating your directory name with single quotes.

$ cd '!)e$!gn&(reate'

That being said, while Ubuntu (Linux) will let you name directories in this way, I would highly recommend against it. Using special characters in directory names can make them difficult to read, and if you are using a reserved character you will always need to escape it or encapsulate the directory name in quotes.

set +H or set +o histexpand to disable the special treatment of !. Add that to your ~/.bash_profile or even some system-wide config file and you'll have one less thing to worry about. Unless you are actually using this feature, that is.
–
MvGApr 23 '14 at 22:28

I'm not sure what this is called, but I call it "passing the file name as a string" since that is what it would be called in programming.
–
JFAApr 24 '14 at 1:02

Double quotes will help with special characters like spaces that aren't interpolated, but won't help with $, ! and the like, which are interpolated. There are two types of strings in bash: double quotes, which allow for interpolation, and single quotes, which don't. (This is why you should always put your regex for grep, sed, etc. in single quotes.)
–
LiviusApr 23 '14 at 22:03