I know that using scp over SSH will copy the files between hosts, but what if I don't want to copy them but instead move them over entirely?

What command could I use using a secure connection over SSH or otherwise?



1 Answer 1


There is no such thing as "move".

On a single filesystem, you can "move" a file by renaming it; the file itself stays in place, but a new name gets added and an old one removed (this is not guaranteed to be atomic, either - if both "a" and "b" exists, then calling mv a b may very briefly have both names refer to the same file "a", before that old name goes away).

To move a file from one place to another in the general case, you need to create a file with the new name, copy the data into it, and then delete the old one. On a local machine, but different filesystems, the "mv" command does that for you behind the scenes - you can see this happen this by running strace mv a /other/filesystem/b.

To do this between computers without a shared network filesystem, you have to do it step by step yourself, e.g. scp a otherhost:/path/to/new/a && rm a (the ampersands mean that the local file is only deleted if scp succeeded, which means it's extremely likely that the remote copy was made successfully).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .