SCP & Rsync Cheatsheet - File Transfer

All essential SCP & Rsync commands organized by use case, with 39+ entries you can copy and run directly. Find the right command fast when you need it.

SysOps·39 commands·Last updated 2026-07-21
Back to SysOps

scp 8

scp file user@host:/path
上传File到远程
scp user@host:/path/file .
从远程下载File
scp -r dir user@host:/path
recursively上传Directory
scp -P 2222 file user@host:/path
指定Port
scp -i ~/.ssh/id_rsa file user@host:/path
指定私钥
scp -C file user@host:/path
启用Compress
scp -q file user@host:/path
silent模式
scp -v file user@host:/path
verboseOutput

rsync 8

rsync file user@host:/path
SyncFile到远程
rsync user@host:/path/file .
从远程SyncFile
rsync -r dir user@host:/path
recursivelySyncDirectory
rsync -a dir user@host:/path
归档模式(保留Permission、时间戳等)
rsync -av dir user@host:/path
归档模式并verboseOutput
rsync -az dir user@host:/path
归档模式并Compress传输
rsync -e "ssh -p 2222" file user@host:/path
指定 SSH Port
rsync -e "ssh -i key" file user@host:/path
指定 SSH 私钥

rsync 6

rsync -av --delete src/ user@host:/path/
Sync并Delete目标端多余File
rsync -av --update src/ user@host:/path/
只SyncUpdate的File
rsync -av --ignore-existing src/ user@host:/path/
Jump过已exists的File
rsync -av --dry-run src/ user@host:/path/
模拟Run(不实际传输)
rsync -av --progress src/ user@host:/path/
Display传输进度
rsync -av --partial src/ user@host:/path/
保留部分传输的File(断点续传)

rsync 5

rsync -av --include="*.txt" src/ dest/
只Synca given type
rsync -av --exclude="*.tmp" src/ dest/
排除a given type
rsync -av --exclude=".git" --exclude="node_modules" src/ dest/
排除多个Directory
rsync -av --exclude-from=exclude.txt src/ dest/
从FileRead排除规则
rsync -av --filter="+ *.txt" --filter="- *" src/ dest/
使用Filter规则

rsync 6

rsync -av --compress src/ dest/
Compress传输
rsync -av --checksum src/ dest/
使用校验和compareFile
rsync -av --size-only src/ dest/
只compareFilesize
rsync -av --modify-window=1 src/ dest/
修改时间窗口(FAT FileSystem)
rsync -av --log-file=rsync.log src/ dest/
记录日志
rsync -av --stats src/ dest/
Display统计信息

Common Patterns 6

rsync -avz --progress --partial file user@host:/path
断点续传大File
rsync -avz --delete src/ user@host:/path/
镜像SyncDirectory
rsync -avz --exclude=".git" --exclude="node_modules" src/ dest/
Sync代码(排除dependencies)
rsync -avz --backup --backup-dir=backup src/ dest/
Sync并backup修改的File
rsync -avz --max-size=100m src/ dest/
限制传输Filesize
rsync -avz --bwlimit=1000 src/ dest/
限制带宽(KB/s)

💡 Tips

  • scp 适合简单File传输,rsync 适合DirectorySync和增量传输。
  • rsync 的 --delete 会Delete目标端多余File,使用前confirm目标端没有重要数据。
  • rsync 的 src/ 和 src 不同:src/ SyncDirectory内容,src SyncDirectory本身。

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Found an error? Report it

Wrong command or description? Open an issue to help us fix it.

Found an error? Report it