Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am remote logged into a Mac and trying to copy a music file from one directory to another, but I am getting an error. I think it's caused by spaces or special characters, but not sure.

the file is:

01 Your Everything (feat. Louisahhh!).m4a

I tried a few variations of the following to cp the file (this is just a test to rename):

cp 01\ Your\ Everything\ (feat.\ Louisahhh!).m4a dd.m4a

I am getting the following error:

-bash: !: event not found

Thanks for reading!

share|improve this question
Ahh, wait adding escape characters to the ! and () characters did the trick. – Mrwolfy Jan 12 '13 at 2:54
brackets should be fine, but it don't like that bang! I was going to suggest using autocomplete (<tab>) to see what the system thinks it's called, but no need now. Maybe next time – mcalex Jan 12 '13 at 2:56
Thanks. I'll give it a try tomorrow, but escaping the brackets as well as the bang seemed to work. – Mrwolfy Jan 12 '13 at 4:23
Next time just do cp "long filename with special characters.m4a" dd.m4a – terdon Jan 12 '13 at 5:37
@terdon: double-quotes won't work, since it still interprets history substitutions (!) in them -- but single-quotes would do the trick. – Gordon Davisson Jan 12 '13 at 6:20
up vote 3 down vote accepted

You need either to enclose your filename in single quotes ' or to escape all the special characters.

  • In your example spaces, parenthesis and the quotation mark need to be escaped. See this list or the shell manual page for the list of special characters and their meaning.

    01\ Your\ Everything\ \(feat.\ Louisahhh\!\).m4a 
  • Or you can use single quotes ' (not double quotes since several characters are still interpreted).

    '01 Your Everything (feat. Louisahhh!).m4a'

    Keep in mind that you if you have a single quote in a file you will have to quote it differently. For a file called It's done:

    'It'\''s done'
share|improve this answer
+1. You can simplify the last example a bit: 'It'\''s done' – glenn jackman Jan 12 '13 at 11:39
@glennjackman Thanks I updated the example – Matteo Jan 12 '13 at 13:06

Your Answer


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.