ditto -- copy directory hierarchies, create and extract archives

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.
     ditto [-v] [-V] [-X] [] src ... dst_directory

copies a file to the supplied dst_file pathname.
     ditto [-v] [-V] [] src_file dst_file

create and extract archives.  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 -c [-z | -j | -k] [-v] [-V] [-X] [] src dst_archive
     ditto -x [-z | -j | -k] [-v] [-V] [] src_archive ... dst_directory

     ditto -h | --help

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, sockets, 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.

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.

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 environment as an alias to --norsrc --noextattr --noacl on the command line.
-X When copying one or more source directories, do not descend into directories that have a different device ID.
-c Create an archive at the destination path. The default format is CPIO, unless -k is given.
CPIO archives should be stored in files with names ending in .cpio.
Compressed CPIO archives should be stored in files with names ending in .cpgz.
-z use gzip(1) compression to create compressed CPIO archives,
-j use bzip2
-k Create or extract from a PKZip archive instead of the default CPIO.
PKZip archives should be stored in filenames ending in .zip.
--zlibCompressionLevel num compression level to use when creating a PKZip archive 0 to 9, where 0 represents no compression, and 9 represents optimal (slowest) compression. By default, ditto will use the default compression level as defined by zlib.
--sequesterRsrc When creating a PKZip archive, preserve resource forks and HFS meta-data in the subdirectory __MACOSX. PKZip extraction will automatically find these resources.
-x Extract the archives given as source arguments. The format is CPIO, unless -k is given.
Compressed CPIO is automatically handled.
 
--keepParent When creating an archive, embed the parent directory name src in dst_archive.
--arch arch Thin Universal binaries to the specified architecture.
  If multiple --arch options are specified then the resulting destination file will contain each of the specified architectures (if they are present in the source file). arch should be specified as "i386", "x86_64", etc.
--bom bom Copy only files, links, devices, and directories that are present in the specified BOM.
--rsrc
--norsrc
Preserve (or don't)resource forks and HFS meta-data.
ditto will store this data in Carbon-compatible ._ AppleDouble files on filesystems that do not natively support resource forks. Default: --rsrc If both --norsrc and --rsrc are passed, whichever is passed last will take precedence.
Both options override DITTONORSRC, unless explicitly specified, --norsrc implies --noextattr and --noacl
 
--extattr
--noextattr
Preserve (or don't) extended attributes (requires --rsrc (or --norsrc). Default: --extattr
--qtn
Preserve (or don't)quarantine information. default: --qtn --noqtn
--acl
--noacl
Preserve (or don't) Access Control Lists (ACLs). Default: --acl  
--nocache Do not perform copies using the Mac OS X Unified Buffer Cache.
Files read and written will not be cached, although
if the file is already present in the cache, the cached information will be used.
 
--hfsCompression When copying files or extracting content from an archive,
if the destination is an HFS+ volume that supports compression, all the content will be compressed if appropriate.
Intended to be used in installation and backup scenarios that involve system files.
--nohfsCompression Do not compress files with HFS+ compression when copying or extracting content from an archive unless the content is already compressed with HFS+ compression. default: --nohfsCompression
--preserveHFSCompression When copying files to an HFS+ volume that supports compression, ditto will preserve the compression of any source files that were using HFS+ compression. Default:--preserveHFSCompression
--nopreserveHFSCompression Do not preserve HFS+ compression when copying files that are already compressed with HFS+ compression.  
--password When extracting a password-encrypted ZIP archive, --password to have ditto to prompt for a password to use to extract the contents of the file. If this option is not provided, and a password-encrypted file is encountered, ditto will display an error message.
-h display full usage.
-V display a line of output to stderr for every file, symbolic link, and device copied.
-v display a line of output to stderr for each source directory copied.

EXAMPLES

copies the contents of src_directory into dst_directory, creating dst_directory if it does not already exist.
ditto src_directory dst_directory
copies the contents of src_directory into dir/dst_directory, creating dir and dst_directory if they don't already exist.
ditto src_directory dir/dst_directory
copies the contents of all of the src directories into dst_directory, creating dst_directory if it does not already exist.
ditto src-1 ... src-n dst_directory
copies the contents of universal_file into thin_file, thinning executable code to ppc-only on the fly.
ditto --arch ppc universal_file thin_file
copies Scripts, skipping any resources or meta-data, to rhost.
ditto -c --norsrc Scripts -|ssh rhost ditto -x --norsrc - ./Scripts
list the files in the CPIO archive archive.cpio.
pax -f archive.cpio
list the files in the compressed CPIO archive archive.cpgz.
pax -zf archive.cpgz
create a PKZip archive similarly to the Finder's Compress functionality.
ditto -c -k --sequesterRsrc --keepParent src_directory archive.zip
list the files in the PKZip archive archive.zip.
unzip -l archive.zip

ERRORS

ditto returns 0 if everything is copied, otherwise non-zero.

ENVIRONMENT

DITTOABORT ditto will call abort(3) if it encounters a fatal error. DITTONORSRC If is set but --rsrc, --extattr, and --acl are not specified,
those additional types of metadata will not be preserved.

BUGS not

ditto doesn't copy directories into directories in the same way as cp(1). In particular,

ditto foo bar

will copy the contents of foo into bar, whereas

cp -r foo bar

copies foo itself into bar.

Though this is not a bug, some may consider this bug-like behavior.
--keepParent for non-archive copies will eventually alleviate this .

SEE ALSO

bom(5), lsbom(8), mkbom(8), cpio(1), zip(1), gzip(1), bzip2(1), tar(1).