用例你想将多个文件复制到不同的远程目录,一般使用scp。但是scp不允许你在一个命令中指定多个目标地址,所以你必须使用多个scp命令。scp-v/file/source1/*username@host_server:/file/destination1scp-v/file/source2/*username@host_server:/file/destination2scp-v/file/source3/*username@host_server:/file/destination3如何用一个命令将多个文件复制到不同的远程目录?方案一最简单的方案是使用SSHFS将远程地址映射到本地,然后使用cp命令。这需要访问SFTP。mkdirhost_serversshfsusername@host_server:/filehost_servercp/file/source1/*host_server/destination1cp/file/source2/*host_server/destination2cp/file/source3/*host_server/destination3fusermount-uhost_serverrmdirhost_server方案2另一种方案是,先在本地获取您的文件顺序,然后复制整个结构。这需要rsyncmkdirdestination1destination2destination3ln-s/file/source1/*destination1ln-s/file/source2/*destination2ln-s/file/source3/*destination3rsync-a--copy-unsafe-linksdestination1destination2destination3username@host_server:/filerm-rdestination1destination2destination3方案三第三种是继续使用scp,但是需要先开启一个master连接指向服务器。在~/.ssh/config中添加ControlMasterautoControlPath~/.ssh/control:%h:%p:%r如果你以与现有连接相同的点(用户、端口、机器)开始ssh会话,第一个两个会话将通过隧道连接到第一个会话。建立第二个连接不需要重新验证并且速度很快。解决方案4可以继续使用scp,但要避免每次都输入用户名和密码。创建密钥对,然后将私钥注入密钥代理ssh-add~/.ssh/id_rsa,这样就不用每次连接都输入任何内容了。但是,方案三和方案四只是折衷方案。参考:https://unix.stackexchange.co...
