2009-07-15 32 views
11

Các GNU/Linux version of cp có một tốt đẹp --update cờ:Làm cách nào để mô phỏng hành vi 'cp --update' trên Mac OS X?

-u, --update bản sao duy nhất khi tập tin NGUỒN mới hơn file đích hoặc khi các tập tin đích là mất tích

Mac OS X version of cp thiếu cờ này.

Cách tốt nhất để có được hành vi của cp --update bằng cách sử dụng chương trình dòng lệnh hệ thống tích hợp là gì? Tôi muốn tránh cài đặt bất kỳ công cụ bổ sung nào (bao gồm phiên bản GNU cp).

Trả lời

16

rsync có một tùy chọn -u/--update rằng hoạt động giống như GNU cp:

$ rsync -u src dest 
4

Ngoài ra nhìn vào tùy chọn rsync của nhau, mà có lẽ là những gì bạn thực sự muốn:

-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. 
Các vấn đề liên quan