Copy files with metadata preserved using cp -p and -a
A plain cp gives every copy a fresh timestamp and the invoking user's permissions; -p and -a are the forgotten flags that keep the originals faithful.
Run `cp -p file.txt dest/` to preserve timestamps and permissions, or `cp -a folder dest/` for an archive-style copy that also recurses and preserves ownership.
01Command
Command
$ cp -p report.txt ~/Archive/report.txt
cp -a ~/Projects ~/Backup/Projects02What it does
-p preserves mode, ownership (when permitted), access and modification times, while -a is shorthand for -pR plus extra fidelity, making it the right choice for backups. Without these flags, a copy's mtime becomes the copy moment, which silently breaks incremental backup tools and make-based builds that rely on timestamps.
03Risk
!Warning: Preserving ownership as a non-root user silently fails for files you don't own; run as root or expect owner changes on restored backups.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- cp — copy files (macOS)Evidence: Documents -p (preserve mode, ownership, timestamps) and -a (archive mode including recursion).
Last verified: 2026-09-17 · Category: Files & Folders