Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
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 at 12:01

2 Answers 2

up vote 3 down vote accepted

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'
share|improve this answer
    
Yep tried that got this error mv: cannot stat `Giko Suzo San\\?e - Ep1.avi': No such file or directory –  user64168 Apr 2 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 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 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 at 12:05
    
Holy cow that last line work. Thank you so much. Been tearing my hair out for hours. :P –  user64168 Apr 2 at 12:28

Auto-complete often fixes problems like this:

mv Giko<tab> "Giko Suzo San’e - Ep1.avi"
share|improve this answer
    
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 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 Apr 2 at 23:20

Your Answer

 
discard

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.