0

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...

JohnRoach
  • 115
  • 1
  • 4

5 Answers5

3

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.

MadHatter
  • 78,442
  • 20
  • 178
  • 229
  • Or `ls -la | cat -vT` – Janne Pikkarainen Dec 05 '11 at 10:33
  • @MadHatter I got a "-rwxrwxrwx 1 ftpuser renko 2798985 2011-10-14 01:12 +13x18_DSC_0800.JPG -rwxrwxrwx 1 ftpuser renko 2567144 2011-10-14 01:12 +13x18_DSC_0848.JPG " – JohnRoach Dec 05 '11 at 10:40
  • @MadHatter Although I haven't been able to resolve this issue without using the joker card i.e. "*". Here is the solution I have been able to find ; #cp *DSC_0800* 13x18_DSC_0800.JPG #rm *+* This seems to do the trick... I still wonder why I couldn't do it without using the * .... Since you reminded me of the * you get the bonus! – JohnRoach Dec 05 '11 at 10:49
1

Use

cp "+13x18_DSC_0800.JPG" 13x18_DSC_0800.JPG
Janne Pikkarainen
  • 31,454
  • 4
  • 56
  • 78
  • Sorry but no cigar you get a : "cp: cannot stat `+13x18_DSC_0800.JPG': No such file or directory" error – JohnRoach Dec 05 '11 at 10:35
0

The accepted answer uses globbing and so requires checking only one file matches. If we prepend a path the reference is unique.

touch +plus.file
touch -minus.file
mv ./+plus.file plus.file
mv ./-minus.file minus.file
flowtron
  • 215
  • 2
  • 5
0

stupid and simple solution if you want to get rid of just one file - use midnight commander :D

but + sign at the beginning shouldn't be a problem at all ...

    $ touch +13x18_DSC_0800.JPG
    $ mv +13x18_DSC_0800.JPG test.jpg
    $ rm test.jpg

works for me ...

Fox
  • 3,887
  • 16
  • 23
  • [edited] actually it did not work... the test.jpg turned out to be a 0 byte file... – JohnRoach Dec 05 '11 at 10:36
  • 1
    touch does create an empty file with that name if it does not exist. i was presenting this as an example of it working. – Fox Dec 05 '11 at 10:42
0

For me

    cp +13x18_DSC_0800.JPG 13x18_DSC_0800.JPG

worked like charm, without any escaping.

Stone
  • 6,941
  • 1
  • 19
  • 33