1

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
  • 2
    Try to use the bash completion by pressing TAB to complete the file name with correct escaping. Commented Jul 17, 2013 at 10:22
  • 1
    What is the output of printf '<%q>\n' *.tar.gz? Commented Jul 17, 2013 at 10:22

2 Answers 2

6

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' .. 
4
  • mv "secret\r-.tar.gz" ../ -> is not working. but mv $'secret\r-.tar.gz' does. Commented Jul 17, 2013 at 10:31
  • Or mv secret\^M-.tar.gz .., where ^M is produced by pressing Ctrl-V, Ctrl-M. Commented Jul 17, 2013 at 10:53
  • 2
    @manatwork, note that the backslash above is not necessary since the CR character is not special to the shell. Commented Jul 17, 2013 at 11:23
  • Of course, is not. Thank you, @StephaneChazelas. Commented Jul 17, 2013 at 11:28
1

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.