rsync 和 --remove-source-files

dam*_*mko 4 rsync

我使用 rsync v.3.0.4,当我需要移动某些内容时,我将其与 --remove-source-files 一起使用。与 mv 相比,我更喜欢 rsync。

不幸的是,当我使用 --remove-source-files 时,目录保留在源端(如 man 中所述)。一旦移动了所有文件,有没有办法也删除目录?

Ted*_*ddy 5

您始终可以通过以下方式手动删除它们:

find /path/to/directory -depth -type d -print0 \
    | xargs --null --no-run-if-empty rmdir --
Run Code Online (Sandbox Code Playgroud)

这只会删除空目录。

  • 当前查找版本的更优雅的解决方案是:“find /path/to/directory -type d -empty -delete” (5认同)