Copy files across servers

At some point, we need to do some file copying on different Linux servers. Of course, if smb sharing is enabled on the windows side, then this record will appear to have no value. Copy files or directories, paste... Isn't there a better way to do this, because after all, sometimes the speed is quite touching.

When we copy files on the same server, we always use the cp command. The protagonist that needs to be introduced at this moment is "SCP"

Introduction of SCP

scp is the abbreviation of secure copy, which is used to remotely copy files under Linux. Similar commands are cp, but cp is only copied locally and cannot be cross-server, and scp transmission is encrypted. It may slightly affect the speed. When your server's hard disk becomes a read-only read only system, scp can help you move the files out. In addition, scp does not occupy resources very much and does not increase the system load much. At this point, rsync is far behind it. Although rsync is faster than scp, when there are many small files, rsync will cause very high hard disk I/O, and scp basically does not affect the normal use of the system.

usage

Here it is assumed that we can access two different servers at the same time, if I am on the s1 server now

Copy a single file

scp  workspace/sourcefile/file.txt   [email protected]:/home/username

Usually if the target server has a password, it will automatically pop up after executing the command and enter the correct password to start copying

Copy entire directory

scp -r workspace/filedir    [email protected]:/home/username

Of course, you can also use tar to compress the directory first, and then copy the equivalent of a single file, personally feel better.

Record it, in case you forget, there are too many practical commands for linux, keep in mind!!!

Guess you like

Origin blog.csdn.net/jeephao/article/details/108856642