rsync命令怎么复制文件
时间: 2024-02-01 18:11:18 浏览: 19
rsync命令可以用于在本地计算机和远程计算机之间,或者两个本地目录之间复制文件。以下是使用rsync命令复制文件的示例:
1. 从本地复制文件到远程计算机:
```shell
rsync [选项] 源文件 目标文件
```
例如,将本地的`/path/to/source/file`复制到远程计算机的`user@remote:/path/to/destination/`:
```shell
rsync /path/to/source/file user@remote:/path/to/destination/
```
2. 从远程计算机复制文件到本地:
```shell
rsync [选项] 用户@远程主机:源文件 目标文件
```
例如,将远程计算机的`user@remote:/path/to/source/file`复制到本地的`/path/to/destination/`:
```shell
rsync user@remote:/path/to/source/file /path/to/destination/
```
3. 在本地计算机之间复制文件:
```shell
rsync [选项] 源文件 目标文件
```
例如,将本地的`/path/to/source/file`复制到本地的`/path/to/destination/`:
```shell
rsync /path/to/source/file /path/to/destination/
```
请注意,上述示例中的选项可以根据实际需求进行调整,例如使用`-a`选项以递归复制文件和目录,并保持文件属性不变。