我正在使用 rsync 从服务器上获取必要的文件,然后在本地拥有这些文件后从服务器中删除这些文件。我正在运行的完整命令如下。
这确实成功删除了源服务器上的文件,但空目录仍然存在。我没有收到任何消息或错误。所有输出正常。也许这是预期的功能。
如何告诉 rsync 清理所有内容,包括目录?
rsync --progress -vrzh --remove-source-files
两端的版本都是 3.0.9。
slh*_*hck 40
手册页甚至说:
--remove-source-files sender removes synchronized files (non-dirs)
Run Code Online (Sandbox Code Playgroud)
如果要删除源中的空目录,如果仍有文件,请执行以下操作:
find . -depth -type d -empty -delete
Run Code Online (Sandbox Code Playgroud)
如果它只是一个空的源目录,一个rmdir <directory>
当然就足够了。
Mar*_*iae 17
--remove-source-files
您观察到的行为正是由 指定的man rsync
:
--remove-source-files
Run Code Online (Sandbox Code Playgroud)This tells rsync to remove from the sending side the files (meaning non-directories) that are a part of the transfer and have been successfully duplicated on the receiving side.
没有删除目录的特定命令,正如StackExchange和ServerFault 中的这两个讨论清楚地显示的那样。解决方案建议发出两个单独的命令:
rsync -av --ignore-existing --remove-source-files source/ destination/ && \
rsync -av --delete `mktemp -d`/ source/
Run Code Online (Sandbox Code Playgroud)
这两篇文章中建议的最后一条命令,
rmdir source/
Run Code Online (Sandbox Code Playgroud)
删除(现已清空)源目录所需的内容在这些帖子中具有这种形式,因为 OP 和答案正在使用 rsync 在同一台机器内移动大量文件。在您的情况下,您必须手动执行此操作。
使用“ rm -rf ”具有固有的竞争条件,您可以即删除刚刚在rsync和rm调用之间创建的文件。
我更喜欢使用:
rsync --remove-source-files -a server:incoming/incoming/ &&
ssh 服务器查找传入 -type d -delete
如果目录不为空,这将不会删除目录。
归档时间: |
|
查看次数: |
34705 次 |
最近记录: |