rsync(用 3.0.9 版检查)有一个选项叫做--remove-source-files它做它所说的。如果您只想删除传输的文件而不传输尚未传输的其他文件,则需要额外使用选项`--existing``。
不幸的是,即使使用了选项,rsync 似乎也不会输出它要删除的文件--verbose --itemize-changes --stats。
# create source and target dirs
mkdir /tmp/source
mkdir /tmp/target
# create a test file in source
touch /tmp/source/test
# rsync source and target
rsync --archive --itemize-changes --verbose --stats /tmp/source/ /tmp/target
# verify that test has been copied to target
[ -f /tmp/target/test ] && echo "Found" || echo "Not found"
# create another file in source
touch /tmp/source/test2
# delete files on source which are already existing on target
rsync --archive --itemize-changes --verbose --stats --remove-source-files --existing /tmp/source/ /tmp/target
# verify that test has been deleted on source
[ -f /tmp/source/test ] && echo "Found" || echo "Not found"
# verify that test2 still exists on source and was not transferred to target
[ -f /tmp/source/test2 ] && echo "Found" || echo "Not found"
[ -f /tmp/target/test2 ] && echo "Found" || echo "Not found"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5777 次 |
| 最近记录: |