如何在Mac OS X上模拟'cp --update'行为?

时间:2009-07-15 16:33:23

标签: macos shell

GNU/Linux version of cp有一个很好的--update标志:

  

-u, - 更新   仅当SOURCE文件比目标文件更新或缺少目标文件时才复制

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

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

2 个答案:

答案 0 :(得分:16)

rsync有一个-u / --update选项,就像GNU cp一样:

$ rsync -u src dest

答案 1 :(得分:4)

另请参阅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.