【问题标题】:How to emulate 'cp --update' behavior on Mac OS X?如何在 Mac OS X 上模拟“cp --update”行为?
【发布时间】:2009-07-15 16:33:23
【问题描述】:

GNU/Linux version of cp 有一个漂亮的 --update 标志:

-u,--更新 仅在源文件比目标文件新或目标文件丢失时复制

Mac OS X version of cp 缺少此标志。

使用内置系统命令行程序获得cp --update 行为的最佳方法是什么?我想避免安装任何额外的工具(包括 GNU 版本的cp)。

【问题讨论】:

    标签: macos shell


    【解决方案1】:

    rsync 有一个 -u/--update 选项,其工作方式与 GNU cp 类似:

    $ rsync -u src dest
    

    【讨论】:

      【解决方案2】:

      另外看看 rsync 的其他选项,这可能是你真正想要的:

          -l, --links                 copy symlinks as symlinks
          -H, --hard-links            preserve hard links
          -p, --perms                 preserve permissions
              --executability         preserve executability
          -o, --owner                 preserve owner (super-user only)
          -g, --group                 preserve group
              --devices               preserve device files (super-user only)
              --specials              preserve special files
          -D                          same as --devices --specials
          -t, --times                 preserve times
      
          -a, --archive
                This is equivalent to -rlptgoD. It is a quick way of saying you want recursion 
                and want to preserve almost everything (with -H being a  notable  omission).   The
                only exception to the above equivalence is when --files-from is specified, in which 
                case -r  is not implied.
      
                Note that -a does not preserve hardlinks, because finding multiply-linked files is
                expensive.  You must separately specify -H.
      

      【讨论】:

        猜你喜欢
        • 2012-03-21
        • 2013-10-29
        • 1970-01-01
        • 1970-01-01
        • 2014-01-24
        • 2010-12-08
        • 1970-01-01
        • 1970-01-01
        • 2016-06-23
        相关资源
        最近更新 更多