zoukankan      html  css  js  c++  java
  • rsync 命令中的路径斜线

    rsync命令大家都知道,但是其中的一个小细节比较容易被忽略,那就是 路径结尾的 “/” ,在路径的结尾有没有斜线,结果是大不同的。现举例说明:

    假设现有两个目录,一个名为sourceDir,另一个名为destinationDir,分别包含如下内容:

    sourceDir/

          a.file
          b.file

    destinationDir/

          1.file

          2.file

    下边两个命令分别演示了尾部斜线的作用:

    rsync /sourceDir    /destinationDir/

    此命令会复制sourceDir目录到destinationDir中,结果如下:

    destinationDir/

          1.file

          2.file

          sourceDir/

                a.file

                b.file

    rsync /sourceDir/    /destinationDir/

    此命令会同步sourceDir目录中的内容到destinationDir中,结果如下:

    destinationDir/

          1.file
          2.file
          a.file
          b.file      

    看到区别了吗?

    源地址尾部斜线告诉rsync "复制这个目录里的内容到目标目录" ,如果不加尾部斜线,那么这个目录本身会被复制到目标地址。

    如果你实在记不住这个区别,那么在源地址的最后使用 /*是最保险的方法

    如果你要做整个的源目录镜像,那么推荐使用下边方法:

    rsync -a --delete /home/mst3k /backup/
     
    Source:
    /home/mst3k/file_a.txt
    /home/mst3k/dir
    /home/mst3k/dir/file_b.txt
     
    Destination:
    /backup/mst3k/file_a.txt
    /backup/mst3k/dir
    /backup/mst3k/dir/file_b.txt
     
    这是推荐的方法,当一个top level 目录在源地址删除时,在目的地址也会自动删除。
    
  • 相关阅读:
    Java-GZIPOutputStream踩坑
    Redis事务
    Netty实现简单群聊
    SpringMVC请求参数解析
    Netty实现WebSocket
    SpringBoot项目war包部署
    NIO实现群聊
    SpringMVC请求映射handler源码解读
    SpringMVC自定义兼容性HandlerMapping
    spring boot自定义类配置绑定在配置文件中自动提示
  • 原文地址:https://www.cnblogs.com/moqiang02/p/4061209.html
Copyright © 2011-2022 走看看