0

I have a remote Debian test server to which I connect via SSH (Putty client). I wanted to move a lot of files on a remote machine to another folder:

remote: /mnt/a/ -> remote: /mnt/b/c/
RESULT@remote: /mnt/b/c/a/

I've used a move (mv) command connecting to a remote computer with SSH from my local computer:

mv /mnt/a/ /mnt/b/c/

I did that with about 700 MB of data (about 5 files) and it took forever to copy those files.

Does the mv command transfer the files to the local computer through SSH and then sends it back to another folder on the server? If so, is there any other command I can use to move the files only locally on the remote server?

  • 1
    Your question is not correct : in your situation, you do not download any file to your local computer. Your issue is not related to ssh but to your Debian server (moving a file to another partition require a copy that can take time, for example). – Uriel Jan 4 '15 at 14:03
  • The mv command you show is not "connecting to a remote computer with SSH from my local computer". It should be a fairly quick operation, unless it's between filesystems in which case it can take a bit of time if the disks are slow or in heavy use. – Kusalananda Jun 21 '16 at 7:59
3

As long as your source and destination paths are on the same filesystem, mv won't actually "move" anything. It'll just edit your directories' and files' metadata (inodes and links), but the data blocks themselves won't move. For instance, assuming that /home and /srv are on different filesystems, you'll observe the following:

$ mv /home/bigfile.txt /home/mydir/ # Instant.
$ mv /home/bigfile.txt /srv # Takes time.

If you're moving all that data from a filesystem to another, then it has to be physically copied from a disk section to another: data blocks need to be moved, and that can take time (and to be honest, you can't do much about it).

Doing it over SSH does not change a thing. SSH stands for Secure Shell, meaning you're getting an actual remote shell, not just using your machine as a relay for everything. Whatever you request from your remote machine through SSH is handled remotely.

  • Yes, it is the same drive, but a different filesystem. I didn't realize that. Thank you! – Joudicek Jouda Jan 4 '15 at 14:07
1

To make moving files via a SSH session more robust I would urge you to use screen (or tmux or something similar). Otherwise you risk your SSH session being interrupted (network glitch, power glitch on local system, accidentally close PuTTY window, Windows goes into standby/hybernate, etc). If your SSH session gets killed then your move operation will be interrupted (unfinished - best case scenario) or data being lost/corrupted (worst case scenario).

Also IMO when moving large amounts of data rsync is a better option. Firstly because you can easily set it to show progress (so you know it hasn't stalled, etc). Secondly because if it is interrupted it can be restarted without having to redo what has successfully been done already...

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.