What is the most accurate way to copy a file or a folder from one linux machine to another using commands?
-
1Possible duplicate of Use scp to transfer a file from local directory X to remote directory Y – jesse_b Nov 15 '18 at 14:42
2 Answers
There are various options like ftp
, rsync
etc. but the most useful of these is the scp
which comes preinstalled with openssh
package. Syntax is simple:
scp file.txt user@host:/folder/to/which/user/has/permissions
There are some other flags, for example, if you are using a different port other than 22
for ssh
, you'd need to mention that in the command with -P
option.
scp -P PORT file.txt user@host:/folder/to/which/user/has/permissions
For directories, it is advised to archive folder(s) in some container. The most easy is one is tar
:
tar -cvf myfolder.tar folder1 folder2 folderN
And then use scp
to send it across to another Linux machine (just replace file.txt
with myfolder.tar
).

- 429
rsync -a
should be as accurate as accuracy can get.
-a
stands for the archive mode.
A good description is given in its man
page:
rsync -avz foo:src/bar /data/tmpThis would recursively transfer all files from the directory src/bar on the machine foo into the /data/tmp/bar directory on the local machine. The files are transferred in "archive" mode, which ensures that symbolic links, devices, attributes, permissions, ownerships, etc. are preserved in the transfer. Additionally, compression will be used to reduce the size of data portions of the transfer.
The compression flag is -z
and -v
switches verbosity on.
Study the man
page to find out much more.