Linux – How to copy a file with filename “+” and rename it

copylinuxrenameUbuntu

I have a file named +13x18_DSC_0800.JPG on a linux server (Please don't ask me how it got there as I have no idea how it got there). I wish to rename it to 13x18_DSC_0800.JPG. However I have not been able to. When I try to copy it I get ;

# cp \+13x18_DSC_0800.JPG asd.JPG
  cp: cannot stat `+13x18_DSC_0800.JPG': No such file or directory

Here is some more inforamtion ;

#ll
 -rwxrwxrwx  1 ftpuser renko 2798985 2011-10-14 01:12  +13x18_DSC_0800.JPG*

I really don't know what is wrong other than that the plus sign is killing some script.
Some more information ;

#uname -a
Linux server-1 2.6.38-8-server #42-Ubuntu SMP Mon Apr 11 03:49:04 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

Any help would be awesome…

Best Answer

Often this means there are some non-printing characters in the filename, which you can't see because they're non-printing.

Try ls -la > /tmp/foo then vi -b /tmp/foo to look at all the text.

If that's the case, the easiest way is to handle it via glob, try echo *13x18_DSC_0800* to verify that the glob matches that file (and only that file), then you can do mv *13x18_DSC_0800* newname.jpeg to rename it.

Related Topic