Somehow i have tar file called 'secret\r-.tar.gz'.
Note that it has \r in the name.

I tried following SSH command for moving but none of them are working:

mv secret\r-.tar.gz ../
mv secret\\r-.tar.gz ../
mv secret\\r-.tar.gz ../
mv "secret\r-.tar.gz" ../

All resulted with error:

mv: cannot stat `secret\r-.tar.gz': No such file or directory

Can you guys point me to the right direction.

  • 2
    Try to use the bash completion by pressing TAB to complete the file name with correct escaping. – Marco Jul 17 '13 at 10:22
  • 1
    What is the output of printf '<%q>\n' *.tar.gz? – Chris Down Jul 17 '13 at 10:22

If the file is literally called secret\r-.tar.gz, mv "secret\r-.tar.gz" ../ should have worked.

If the \r is really a carriage return, you need to have a literal carriage return (and not an escape):

mv $'secret\r-.tar.gz' ..
| improve this answer | |
  • mv "secret\r-.tar.gz" ../ -> is not working. but mv $'secret\r-.tar.gz' does. – MagePsycho Jul 17 '13 at 10:31
  • Or mv secret\^M-.tar.gz .., where ^M is produced by pressing Ctrl-V, Ctrl-M. – manatwork Jul 17 '13 at 10:53
  • 2
    @manatwork, note that the backslash above is not necessary since the CR character is not special to the shell. – Stéphane Chazelas Jul 17 '13 at 11:23
  • Of course, is not. Thank you, @StephaneChazelas. – manatwork Jul 17 '13 at 11:28

You can generally use globbing (* or ?) to deal with hard-to-type characters in file names. For example:

mv secret?-.tar.gz something-more-appropriate.tar.gz

You might want to use echo or ls first to be sure of what you're getting.

| improve this answer | |

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.