0

What is the most accurate way to copy a file or a folder from one linux machine to another using commands?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Janith
  • 191

2 Answers2

2

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).

sla3k
  • 429
0

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/tmp

    This 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.