语法:
rsync [options] user@remote_host:/path/to/remote/source /path/to/local/destination
示例:
rsync -avz -e ssh user@remote_host:/path/to/remote/source/ /path/to/local/destination/
语法:
rsync [options] /path/to/local/source user@remote_host:/path/to/remote/destination
示例:
rsync -avz -e ssh /path/to/local/source/ user@remote_host:/path/to/remote/destination/
-a
:归档模式,表示递归传输并保持文件属性。-v
:详细输出,显示传输过程中的信息。-z
:压缩文件数据在传输过程中减少带宽使用。-e ssh
:指定使用 SSH 作为远程 shell。有时会遇到权限问题,可以使用 sudo
提升权限:
sudo rsync -avz -e ssh user@remote_host:/path/to/remote/source/ /path/to/local/destination/
sudo rsync -avz -e ssh /path/to/local/source/ user@remote_host:/path/to/remote/destination/
如果要排除某些文件或目录,可以使用 --exclude
选项:
rsync -avz --exclude 'excluded_dir' -e ssh user@remote_host:/path/to/remote/source/ /path/to/local/destination/
rsync -avz --exclude 'excluded_file' -e ssh /path/to/local/source/ user@remote_host:/path/to/remote/destination/
为了更好地了解传输进度,可以添加 --progress
选项:
rsync -avz --progress -e ssh user@remote_host:/path/to/remote/source/ /path/to/local/destination/
rsync -avz --progress -e ssh /path/to/local/source/ user@remote_host:/path/to/remote/destination/