2

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!

5
  • 1
    Ahh, wait adding escape characters to the ! and () characters did the trick.
    – OWolf
    Jan 12, 2013 at 2:54
  • 2
    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, 2013 at 2:56
  • 1
    Thanks. I'll give it a try tomorrow, but escaping the brackets as well as the bang seemed to work.
    – OWolf
    Jan 12, 2013 at 4:23
  • Next time just do cp "long filename with special characters.m4a" dd.m4a
    – terdon
    Jan 12, 2013 at 5:37
  • 2
    @terdon: double-quotes won't work, since it still interprets history substitutions (!) in them -- but single-quotes would do the trick. Jan 12, 2013 at 6:20

1 Answer 1

3

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'
    
1
  • +1. You can simplify the last example a bit: 'It'\''s done' Jan 12, 2013 at 11:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .