Yes, you can use the ditto command in the macOS Terminal to copy files and directories, preserving metadata, resource forks, and file permissions more faithfully than a basic cp command. You enter ditto followed by a source path and a destination path, and it copies the item—including the entire folder structure if the source is a directory—while maintaining extended attributes and other Mac-specific data. This makes ditto a reliable choice for creating backups, cloning folders, or moving projects between drives on a Mac.
What Is ditto and Why Use It?
ditto is a command-line utility that has shipped with macOS (and its predecessor, Mac OS X) for decades. It was originally designed to copy files while preserving the HFS metadata that ordinary Unix tools like cp often drop. On modern macOS, that metadata includes extended attributes (such as the com.apple.quarantine flag), resource forks, ACLs (access control lists), and Finder flags like the hidden or locked bit.
When you copy a folder with cp -R, you get the files and basic permissions, but you can lose these extra layers. ditto handles them natively, which is why it is often the recommended tool for making a bootable backup or transferring an app that relies on special file properties.
Basic Syntax and Examples
The general syntax is:
ditto [options] source destination
Here are the most common forms you will actually type:
- Copy a single file:
ditto ~/Documents/report.pdf ~/Desktop/report.pdf - Copy an entire folder:
ditto ~/Projects/MyApp /Volumes/Backup/MyApp— this createsMyAppat the destination if it does not exist, or merges into it if it does. - Copy a folder and give the destination a new name:
ditto ~/Projects/MyApp /Volumes/Backup/MyApp-Copy - Copy the contents of a folder into an existing folder:
ditto ~/Projects/MyApp/ /Volumes/Backup/ExistingFolder/— note the trailing slashes; this copies the items insideMyAppintoExistingFolderrather than creating a nestedMyAppsubfolder.
If the destination path does not exist, ditto creates it. If it does exist, ditto merges the source into it, overwriting files with the same name while leaving other files in the destination untouched. That is different from cp, which may prompt or behave differently depending on flags.
Useful Options and Flags
While plain ditto works for most tasks, a few options make it more flexible:
-V(verbose): prints one line per file copied. Useful for confirming progress on large folders.-k: creates or extracts a PKZip archive instead of a plain folder copy. For example,ditto -c -k --sequesterRsrc --keepParent sourceFolder archive.zipcreates a zip that preserves Mac metadata.-x: extracts an archive.ditto -x -k archive.zip destinationFolderunzips the file.--norsrc: do not preserve resource forks and metadata. This is rarely needed, but can be useful when copying to a filesystem that does not support them.--rsrc: explicitly preserve resource forks (this is the default on HFS+ and APFS, so you usually do not need it).
For most everyday copying, you will not need any options. Just type the command with source and destination, and let ditto do its job.
ditto vs. cp: Which Should You Use?
The standard cp command is fine for quick copies of individual files or when you do not care about extended attributes. But for directories, especially those containing app bundles, package contents, or files with quarantine flags, ditto is safer.
Key differences:
- Metadata preservation:
dittopreserves extended attributes and resource forks by default;cpdoes not (unless you usecp -por-a, and even then it may not capture everything). - Overwrite behavior:
dittomerges into an existing destination without asking;cp -Rmay overwrite or error depending on the situation. - Archive support:
dittocan create and extract zip files;cpcannot. - Speed: For very large folders,
cpcan sometimes be faster because it does less metadata work. But the difference is usually negligible for typical use.
If you are copying a folder to a USB drive, a network share, or a backup disk, use ditto. If you are just copying a few loose files within the same folder, cp is fine.
Common Mistakes and How to Avoid Them
Even experienced users trip up on a few things:
- Forgetting the destination name:
ditto sourceFolder /Volumes/Backupwill copy the folder itself into/Volumes/Backup, creating/Volumes/Backup/sourceFolder. If you want the contents ofsourceFolderto go directly into/Volumes/Backup, add a trailing slash to the source:ditto sourceFolder/ /Volumes/Backup/. - Assuming overwrite is clean:
dittodoes not delete extra files in the destination. If you are syncing a folder and want the destination to be an exact mirror, you need to delete the destination first or use a tool likersyncwith the--deleteflag. - Using
dittowith special files:dittomay not handle symbolic links exactly likecp -R. It tends to copy the link itself, not the target, which is usually what you want, but be aware if you rely on symlinks. - Not checking permissions: If you get a “Permission denied” error, you may need to use
sudobefore the command, especially when copying to system locations or other users’ folders.
Using ditto to Create and Extract Zip Archives
One of the hidden superpowers of ditto is its ability to create and extract zip files while preserving Mac metadata. This is why it is the engine behind the “Compress” option in Finder.
To create a zip archive of a folder:
ditto -c -k --sequesterRsrc --keepParent MyFolder MyFolder.zip
-c: create an archive-k: use PKZip format (instead of the default CPIO)--sequesterRsrc: store resource forks in the__MACOSXfolder inside the zip (so Windows users can still open it)--keepParent: include the top-level folder in the archive, so extracting gives youMyFolderrather than its contents scattered
To extract a zip:
ditto -x -k MyFolder.zip destinationFolder
This is often more reliable than the unzip command when the zip contains Mac-specific metadata.
Frequently Asked Questions
Does ditto work on all Macs?
Yes, ditto has been part of macOS for decades and is available on every Mac that runs a modern version of macOS. You can access it from the Terminal app, which is in /Applications/Utilities/.
Will ditto copy a folder to an external drive formatted as exFAT?
Yes, but with a caveat: exFAT does not support resource forks or many extended attributes. ditto will still copy the files, but it may drop metadata that cannot be stored on that filesystem. For a backup that preserves everything, use an APFS or HFS+ formatted drive.
How do I see what ditto is doing?
Add the -V flag to print each file as it is copied. For example: ditto -V ~/Documents /Volumes/Backup/Documents. This is helpful for large copies where you want to confirm progress.
Can I use ditto to copy a file to the same directory with a new name?
Yes, just specify the new name in the destination path. For example, ditto file.txt file-copy.txt creates a copy in the current directory. If you use the same name, ditto will overwrite the original without warning.
Is ditto safe for system files?
It is safe in the sense that it will not corrupt files, but copying system files to the wrong location can cause problems. If you are trying to modify system directories, you should use sudo and be very careful about the destination. For normal user files, no special caution is needed.
What is the difference between ditto and rsync?
rsync is designed for syncing and can copy incrementally (only changed parts), preserve permissions, and delete extra files in the destination. ditto is simpler and always copies everything. For one-off copies, ditto is easier; for ongoing backups or mirroring, rsync is more powerful.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Handwriting vs Typing for Digital Note Taking2,400 words
- Configure SSL Certificate HAProxy: Step-by-Step
- Can a Ford Sedan Beat a Mustang? Facts
- Toyota RAV4 Most Expensive Trim: Worth It?
- Ryobi Hybrid Tools: Smart Buy? Here’s Why
- M4 vs M3: Apple Silicon Compared