macos - OSX 上的 cp 和 ditto 命令有什么区别?

标签 macos

我想知道 OSX 上 cp 和 ditto 命令之间的确切区别是什么?

这两个命令的主要区别是什么?

最佳答案

实际上手册页中的标题描述了差异:

  • cp - 复制文件和目录

  • 同上 - 复制目录层次结构,创建和提取文件

手册页中的更多信息

  • cp
cp [OPTION]... [-T] SOURCE DEST

cp [OPTION]... SOURCE... DIRECTORY

cp [OPTION]... -t DIRECTORY SOURCE...

Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

  • 同上
ditto [-v] [-V] [-X] [<options>] src ... dst_directory.

ditto [-v] [-V] [<options>] src_file dst_file

ditto -c [-z | -j | -k] [-v] [-V] [-X] [<options>] src dst_archive

ditto -x [-z | -j | -k] [-v] [-V] [<options>] src_archive ...
       dst_directory

In its first form, ditto copies one or more source files or directories to a destination directory. If the destination directory does not exist it will be created before the first source is copied. If the destination directory already exists then the source directories are merged with the previous contents of the destination.

In its second form, ditto copies a file to the supplied dst_file path- name.

The next two forms reflect ditto's ability to create and extract ar- chives. These archives can be either CPIO format (preferred for unix content) or PKZip (for Windows compatibility). src_archive (and dst_archive) can be the single character '-', causing ditto to read (write) archive data from stdin (or to stdout, respectively).

ditto follows symbolic links provided as arguments but does not follow any links as it traverses the source or destination hierarchies. ditto overwrites existing files, symbolic links, and devices in the destination when these are copied from a source. The resulting files, links, and devices will have the same mode, access time, modification time, owner, and group as the source items from which they are copied. Pipes, sock- ets, and files with names beginning with .nfs or .afpDeleted will be ignored. ditto does not modify the mode, owner, group, extended attributes, or ACLs of existing directories in the destination. Files and symbolic links cannot overwrite directories or vice-versa.

ditto can be used to "thin" Universal Mach-O binaries during a copy. ditto can also copy files selectively based on the contents of a BOM ("Bill of Materials") file. ditto preserves file hard links (but not directory hard links) present in the source directories and preserves setuid and setgid modes when run as the superuser.

ditto will preserve resource forks and HFS meta-data information when copying unless instructed otherwise using --norsrc . Similarly, ditto will preserve extended attributes and Access Control Lists (ACLs) unless --noextattr or --noacl is passed. DITTONORSRC can be set in the environ- ment as an alias to --norsrc --noextattr --noacl on the command line.

关于macos - OSX 上的 cp 和 ditto 命令有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40974029/

相关文章:

macos - 如何使用 Swift 4 Xcode 10 从 Cocoa 中的 Storyboard 以编程方式设置初始 Controller ?

node.js - 为什么重启会恢复 Node 版本

ios - 找不到 QuartzCore/CAMetalLayer.h 文件

Java 程序在 6 小时内崩溃,核心转储错误

JsonConvert 在 Newtonsoft 和 System.Net.Http.Formatting Visual Studio 2017 for Mac 中都存在

R 警告 "IMKClient Stall detected"

swift - 如何防止用户与最前面的自定义 View 后面的对象进行交互?

c - main 的 apple 参数中的 ptr_munge 是什么?

macos - 如何阻止 XCode 下载和安装 iOS 和 OSX 库?

multithreading - Mac OS 访问数据模型时是否会调用诸如drawRect : concurrently from different threads? 这样的显示方法,这不是很危险吗?