rsync 移动文件,保留目录?

rsync 移动文件,保留目录?

我用来rsync在内部和外部硬盘驱动器之间复制数据。它已完成我需要的操作,但我的内部硬盘驱动器空间不足。那么,有什么方法可以像而不是那样rsync发挥作用,但也将空目录的“骨架”留在原始位置,仅删除文件,以便我可以将更多文件放入目录中,然后再次添加将新文件复制到外部驱动器,而不删除旧文件?mvcprsync

或者,如果有一个不rsync支持 Linux 的程序可以完成此任务,那也很好。

答案1

有一个特殊的选项rsync

   --remove-source-files
          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.

          Note that you should only use this option on source  files  that
          are quiescent.  If you are using this to move files that show up
          in a particular directory over to another host, make  sure  that
          the  finished  files  get renamed into the source directory, not
          directly written into it, so that rsync can’t possibly  transfer
          a  file that is not yet fully written.  If you can’t first write
          the files into a different directory, you should  use  a  naming
          idiom  that lets rsync avoid transferring files that are not yet
          finished (e.g. name the  file  "foo.new"  when  it  is  written,
          rename  it  to  "foo"  when  it is done, and then use the option
          --exclude='*.new' for the rsync transfer).

          Starting with 3.1.0, rsync will  skip  the  sender-side  removal
          (and  output an error) if the file’s size or modify time has not
          stayed unchanged.

目的地文件删除取决于您的选择。但是,公平地说,当您不使用任何--delete--delete-before等选项时,它不会删除任何内容。

相关内容