I have a problem renaming a file that I'm not even sure which special characters I have in the file. I'm using CentOS 6 64bit.

When I ls the file:

Giko Suzo San?e - Ep1.avi

but when view it in FTP:

Giko Suzo San’e - Ep1.avi

When I try to mv it:

[root@server ]# mv 'Giko Suzo San?e - Ep1.avi' 'Giko Suzo Sane - Ep1.avi' mv: cannot stat `Giko Suzo San?e - Ep1.avi': No such file or directory

I also tried renaming it in FTP using FlashFXP. I get:

[L] 550 Giko Suzo San’e - Ep1.avi: No such file or directory Rename Failure!

How can I rename with this problem?

  • 2
    It's probably not actually a question mark. Try printf '"%s"\n' ./Giko Suzo San*Ep1.avi to see what it is. And if that only returns one result do printf 'mv "%s" ./Giko_Suzo_San.Ep1.avi\n' ./Giko Suzo San*Ep1.avi | . /dev/stdin – mikeserv Apr 2 '14 at 12:01

You could use \ before the character ? so it is consider as a normal character in the name of the file and not a special character to be interpreted.

The command would then be:

mv Giko\ Suzo\ San\?e\ -\ Ep1.avi 'Giko Suzo Sane - Ep1.avi'

EDIT: following discussion in comments, this line did the trick:

mv Giko\ Suzo\ Sa*\ -\ Ep1.avi 'Giko Suzo Sane - Ep1.avi'
  • Yep tried that got this error mv: cannot stat `Giko Suzo San\\?e - Ep1.avi': No such file or directory – user64168 Apr 2 '14 at 11:55
  • @Laurent If quotes(single or double) are used in the filename there is no need of \ before ?. mv 'Giko Suzo San?e - Ep1.avi' newfilename or mv Giko\ Suzo\ San\?e\ -\ Ep1.avi newfilename can be used – sher Apr 2 '14 at 12:01
  • mv 'Giko Suzo Sa* - Ep1.avi' didn't work `'Giko Suzo San?e - Ep1.avi' didn't work either. I think was name using some other language that unix can not recognize. – user64168 Apr 2 '14 at 12:05
  • As the problem seems to be the ? which s not recognized as a simple ? (otherwise it should work), maybe you can try using: mv Giko\ Suzo\ Sa*\ -\ Ep1.avi 'Giko Suzo Sane - Ep1.avi' – Laurent C. Apr 2 '14 at 12:05
  • Holy cow that last line work. Thank you so much. Been tearing my hair out for hours. :P – user64168 Apr 2 '14 at 12:28

Auto-complete often fixes problems like this:

mv Giko<tab> "Giko Suzo San’e - Ep1.avi"
  • I tried auto-complete with tab but it wouldn't do anything, it work for other file but this one. I'm not sure why. – user64168 Apr 2 '14 at 11:54
  • @user64168 Probably because the file name is in a different encoding from the one in the shell where you tried this, causing the shell to see an invalid character. – Gilles 'SO- stop being evil' Apr 2 '14 at 23:20
  • Right, this must in fact be a unicode character that only looks like an ordinary "apostrophe". – syntaxerror Sep 15 '15 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.