6

I was attempting to utilize the mv command to move a file onto a remote server. I ended up executing the command...

mv sqlreport.php myuser@mywebsite.org

Unfortunately, this did not work. Worse, my file seems to have disappeared. A new file, myuser@mywebsite.org, has appeared, but it is not a directory (In that I cannot cd into it).

Any tips on where my file may have gone, and how to rescue it?

  • 6
    You went wrong in that mv is not capable of moving a file to a remote location. You will need something like curl or scp. – HalosGhost Jun 24 '14 at 05:17
  • @HalosGhost If you replace mv with scp you will end up with the same result. You will need to scp to user@host.org: at least. – Bernhard Jun 24 '14 at 06:00
  • 4
    @Bernhard, I did not mean to (nor do I feel that I did) imply that either curl or scp were 1:1 replacements for mv using the syntax the OP used. They are, however, tools that can be used for what the OP wants. – HalosGhost Jun 24 '14 at 06:01
  • @HalosGhost I was not in the impression that you didn't know, but I thought that your post might have been interpreted like that by Austin. – Bernhard Jun 24 '14 at 06:40
  • Fair enough. You are certainly correct; curl and scp certainly have a different syntax than mv. – HalosGhost Jun 24 '14 at 06:41
  • 32
    "Worse, my file seems to have disappeared. A new file, myuser@mywebsite.org, has appeared" What MIGHT be the content of that file? Don't you want to guess? – glglgl Jun 24 '14 at 14:02
  • In linux, the mv command is used to rename files (as well as move them). – gen_Eric Jun 24 '14 at 15:01
  • @RocketHazmat what would the difference be? – Carl Witthoft Jun 24 '14 at 17:03
  • 2
    @CarlWitthoft: Well, when you "rename", you are just "moving" the file to a new one with a new name :D – gen_Eric Jun 24 '14 at 17:08
  • 3
    The new file is not a directory? Impressive. Was the old file a directory? – R. Martinho Fernandes Jun 25 '14 at 15:06

4 Answers4

44

You have renamed your file to myuser@mywebsite.org.Try renaming it back:

mv myuser@mywebsite.org sqlreport.php
9

Your file is not vanished,You have just renamed it. You can rename it back to sqlreport.php using the following command mv myuser@mywebsite.org sqlreport.php. To copy your file to remote host you can use the scp command. scp sqlreport.php myuser@mywebsite.org:/remote/directory/path. If you want to copy a directory to remote host then you can use -r option suffix to scp.

Thushi
  • 9,498
  • 1
    And while we're at it: You need to put at least a colon at the end of the remote target (useful for copying something to a remote home directory) or scp works just like cp. Happens to me all the time and I always wonder briefly why my file isn't there. – musiKk Jun 24 '14 at 19:51
4

The key insight is that, in Unix, a filename can contain any character at all, except for '/' and the null character. So, when you type mv file user@host, it moves file file to file user@host, even though the new name contains funny characters such as '@' and '.'.

(As per MvG's comment, things get a little more complex in the brave new world of Unicode but, for 8-bit character sets, the above remains true.)

  • 2
    Better make that “any byte at all”, since the interpretation as characters depends on locale. In some encodings, UTF-8 for example, there might even be byte combinations which don't correspond to characters. – MvG Jun 24 '14 at 14:54
  • 2
    Yep. As far as the kernel is concerned, pathnames are arbitrary strings of bytes, and the only bytes with any defined meaning are 0x2f (ASCII /, component separator) and 0x00 (end of C-string). Defining a general mapping of these byte sequences to character sequences is entirely user space's problem. (Some filesystems, e.g. NTFS, impose more complicated rules, coming as they do from OSes with more complicated pathname semantics.) – zwol Jun 24 '14 at 15:17
  • @Zack still, even in NTFS there's a POSIX name subsystem. – Ruslan Jun 25 '14 at 15:21
2

In your case your file got renamed to myuser@mywebsite.org

Try using scp to copy the file to remote location

upkar
  • 326