V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Zien
V2EX  ›  Unix

mv 命令文件夹后面加斜杠真的没有意义吗?

  •  
  •   Zien · Aug 12, 2021 · 2245 views
    This topic created in 1730 days ago, the information mentioned may be changed or developed.

    大部分都说没有作用(我以前也是这样认为的),但看到一个回答建议 source 后不加斜杠,防止 symlink 的问题; target 最好加斜杠,防止错拼导致的问题。

    https://stackoverflow.com/a/24925767

    感觉有点没吃透,有没有大手子能解释下。

    2 replies    2021-08-13 08:02:19 +08:00
    Kobayashi
        1
    Kobayashi  
       Aug 13, 2021 via Android
    target 不知道。source 不加,BSD 下 source/ 表示目录下所有内容。rsync 和 docker cp 中对 source 也有这种区分。
    https://wiki.archlinux.org/title/rsync#As_cp/mv_alternative
    https://stackoverflow.com/questions/37483293/what-are-the-reasons-docker-cp-works-differently-to-unix-cp
    AllenHua
        2
    AllenHua  
       Aug 13, 2021 via iPhone
    另外还有一点比较值得注意,同步文件时,假如 source 是一个文件夹,那么最后一个文件夹带不带斜杠在同步到目标路径后会有一些区别。

    情形 1: rsync -a /file/source/path1 /file/destination/path2

    情形 1 中,最终在 path2 中行程的文件结构是 /file/destination/path2/path1

    情形 2: rsync -a /file/source/path1/ /file/destination/path2

    情形 2 中,最终将 path1 文件夹里面的所有文件都拷贝到了 path2 中。

    https://hellodk.cn/post/591 ( openwrt 通过 opkg 安装 rsync | rsync 基本用法介绍教程)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1065 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 22:51 · PVG 06:51 · LAX 15:51 · JFK 18:51
    ♥ Do have faith in what you're doing.