Copying a Directory Tree, Measured: cp -a vs rsync -a vs tar-pipe
The same three tools copy the same two corpora, and the winner flips with the shape of the data. On a 10,000-file tree the tar pipe is fastest; on a single 1 GiB file cp -a is fastest; rsync -a is slowest on both. The speed table is only half the guide: a missing trailing slash nests the whole tree one level down, and tar's default archive format keeps whole-second timestamps but drops the nanoseconds.
Written November 10, 2026 · Tested with rsync 16.59 · 12 min read
- The table: the winner flips by shape
- Two published claims, both right on different shapes
- The trailing slash that nests your tree
- tar keeps the seconds, not the nanoseconds
What this guide is
Two corpora, three arms, three reps each. The tree is 10,000 files of 1 KiB each, flat, with deterministic seeded content, about 10 MB in total. The file is a single 1 GiB file of random bytes. Every arm copies each corpus into a fresh empty destination, and every rep is checked the same way: the tree against a manifest of per-file sha256, size, mode, and mtime, the file against its sha256 and size, so a timing number can never come from a run that copied something different. The question is the one people ask before duplicating a project directory or staging a disk image: which tool copies it fastest, and what does each tool get wrong that the clock does not show.
The answer is a correction in both directions. There is no fastest tool, only a fastest tool for a shape. On the tree the tar pipe wins by a clear margin; on the single file cp -a wins by a factor of two. Rsync -a is slowest on both shapes, which is the price of the machinery that makes it the right tool for the second copy, not the first. And the two traps decide more real copies than the speed table does: rsync without a trailing slash puts the tree inside a directory named after itself, and tar's default archive format rounds every timestamp to the whole second.
The table: the winner flips by shape
Wall seconds, medians of three runs, fresh tonight. Every rep returned rc=0, and every tree rep matched its manifest and every file rep matched its sha256.
cp -a, tree: fresh median 0.2764, reps 0.2911, 0.2764, 0.2398. Night before: 0.3040, reps 0.3052, 0.3040, 0.2440.rsync -a, tree: fresh median 0.3810, reps 0.3810, 0.3895, 0.3551. Night before: 0.4015, reps 0.4015, 0.3958, 0.4054.tar -cf - | tar -xf -, tree: fresh median 0.1581, reps 0.1479, 0.1609, 0.1581. Night before: 0.1447, reps 0.1806, 0.1401, 0.1447.cp -a, 1 GiB file: fresh median 0.4489, reps 0.9421, 0.4489, 0.3695. Night before: 0.4067, reps 2.3749, 0.4067, 0.3751.rsync -a, 1 GiB file: fresh median 1.7956, reps 1.7956, 1.7522, 1.9923. Night before: 1.7787, reps 1.7787, 1.7405, 2.1536.tar -cf - | tar -xf -, 1 GiB file: fresh median 0.8988, reps 0.8680, 0.8988, 1.4741. Night before: 1.1727, reps 0.9395, 1.1727, 1.5082.
On the tree, the tar pipe is fastest at 0.1581 seconds: 1.75 times faster than cp -a tonight (2.10 the night before) and 2.41 times faster than rsync -a (2.77 the night before). Rsync -a is 1.38 times slower than cp -a on the tree (1.32 the night before). On the single file, cp -a is fastest at 0.4489 seconds: 2.00 times faster than the tar pipe tonight (2.88 the night before) and 4.00 times faster than rsync -a (4.37 the night before). Rsync -a is 2.00 times slower than the tar pipe on the file (1.52 the night before). The ranking is identical on both nights and every ratio moved by less than a third, so the flip is stable and the exact ratios are one machine's.
Two cells are noisy and the guide says so rather than hiding it. The tar pipe on the single file ranges from 0.87 to 1.47 seconds tonight and 0.94 to 1.51 the night before, with the median moving 1.1727 to 0.8988 across nights; report the range, not just the median, and the tar-beats-rsync ordering on the file still holds on both nights, since tar's worst rep (1.51) stays under rsync's best (1.74). The cp -a first rep on the single file is the cold spike both nights: 0.9421 seconds tonight and 2.3749 the night before against medians near 0.41 to 0.45. A one-run timing of cp -a on a cold file would report two to six times the steady cost. The tree cells sit near the spawn-and-read floor at 0.14 to 0.40 seconds, so treat the tree ratios as order-of-magnitude; the tar pipe's tree win and the cp -a file win are the stable claims.
Two published claims, both right on different shapes
Two published tables contradict each other, and this probe adjudicates them. CopyProgramming's folder-copy guide publishes one unreplicated 10 GB table, cp -a 2 minutes 41 seconds against rsync -a 3 minutes 12 seconds, with no tar-pipe arm, one shape, no reps stated, and no output verification; the same guide asserts tar can be 8 times faster for millions of small files, citing one production scenario with parallelized tar, not a plain tar pipe. The dar project's 2020 backup benchmark, one unreplicated run on a full 4.1 GB Linux system install of 136,837 files, reports cp 5.15 seconds, tar 8.04 seconds, rsync 16.59 seconds, and concludes cp is always fastest.
Both are right, on different shapes, and both are one run on one shape. On a single large file this probe agrees with dar: cp -a is fastest, 2.00 times the tar pipe tonight. On a many-small-file tree this probe agrees with the tar claim's direction: the tar pipe is fastest, 1.75 times cp -a tonight. Neither published table varies the corpus shape, runs reps, or verifies outputs, which is exactly the gap this probe fills: two shapes, three reps each, every rep verified against a manifest or a sha256. The freshest neighboring work, a November 2026 NAS-to-NAS piece, measures cp against rsync on a single 15 GiB file over NFS and finds the same direction, cp at 479 to 494 MB/s against one rsync process at 181 MB/s, but it is a network migration with no tar arm and no tree shape, so it is a different job.
The trailing slash that nests your tree
The trap is one character, and it reproduces with a zero exit code. Run rsync -a tree_src dst/ with no trailing slash on the source and rsync creates dst/tree_src/ and leaves zero files at the top level of dst/. The probe ran it tonight and the night before with the same result both times: rc=0, nested directory present, top-level file count 0. A script that then reads dst/file-00000.bin finds nothing, and a script that counts the destination finds zero files, while rsync reports success.
The manual states the rule directly: a trailing slash on the source changes the behavior to avoid creating an additional directory level at the destination, and a trailing slash means copy the contents of this directory as opposed to copy the directory by name. The two correct forms are rsync -a tree_src/ dst/ for the contents, or rsync -a tree_src dst/ when the nested directory is what you want. The timed tree arm in this probe uses the trailing-slash form, rsync -a tree_src/ dst/, which is why its manifest matches. Cp has the same shape of trap in the other direction: cp -r /source_folder /destination_folder creates a copy of the folder inside the destination when the destination exists, and the copyprogramming guide documents both forms. The fix in both cases is to check the destination listing before trusting the command, not after.
tar keeps the seconds, not the nanoseconds
The tar pipe's tree copies match the manifest on size, mode, sha256, and whole-second mtime on all three reps on both nights, but never on nanosecond mtime: ns_mtime_match is 0 on all six tar-pipe tree reps. Cp -a and rsync -a preserve nanosecond mtime, with a full manifest match on all six of their tree reps each. GNU tar in its default gnu format stores mtime at one-second resolution, so a tar-pipe copy drops the sub-second part of every file's timestamp, truncating it to the whole second below. The tar manual names the formats: ustar is the POSIX 1003.1-1988 format, and posix is the POSIX 1003.1-2001 pax format, which stores sub-second times.
That matters exactly where timestamps decide the next step. A build system, a backup tool, or an rsync quick check that compares mtime at nanosecond precision will see every file in a tar-pipe copy as changed, because the copied mtime is not the source mtime. The fix is --format=posix, which the probe did not measure; this guide states it as the documented option, not as a measured result. If the destination only needs second precision, the tar pipe's rounding is invisible, and the speed win stands. If it needs exact timestamps, cp -a or rsync -a is the tool, and the tar pipe's tree win does not apply.
One more rsync detail the probe verified rather than assumed: there is no separate --whole-file arm in the table because local rsync already defaults to whole-file transfers. The rsync manual says --no-whole-file disables whole-file updating when it is enabled by default for a local transfer, so the -a arm here already copies whole files, and the delta-transfer machinery that makes rsync slow on first copy is not even running. Rsync is slowest on both shapes with its cheapest local mode on.
Checklist
- Before picking a copy tool, check the shape: on a 10,000-file tree the tar pipe is fastest at 0.1581 seconds, 1.75 times cp -a tonight, while on a single 1 GiB file cp -a is fastest at 0.4489 seconds, 2.00 times the tar pipe.
- Before trusting rsync -a on speed, check the table: it is slowest on both shapes, 0.3810 seconds on the tree and 1.7956 on the file, and its value is the second copy, not the first.
- Before running rsync on a directory, check the trailing slash: without it the tree lands one level down in
dst/tree_src/with zero files at the top level, and rsync still exits 0. - Before using a tar pipe where timestamps decide the next step, check the mtime: tar's default gnu format keeps whole-second mtime and drops the nanoseconds on every file, all six reps, while cp -a and rsync -a preserve them.
- Before quoting a ratio, check the range: the tar pipe on the single file spans 0.87 to 1.47 seconds tonight, and cp -a's first rep on the file is 0.9421 seconds against a 0.4489 median, so single runs lie.
- Before reusing these numbers, check the setup: WSL2, 32 CPUs, cp 9.4, rsync 3.2.7, tar 1.35, tmpfs, warm page cache, one thread per arm, flat 10,000-file tree plus one 1 GiB random file, sha256 recorded in the probe log.
Related guides on this site
- Copying a 1 GiB File: dd at bs=512 Is 9x Slower — and cp Ties dd Once the Block Size Is Right
- Copying a Sparse File, Measured: Which Tools Preserve the Holes
- Copying a File Without read() and write() Is About Twice as Fast: sendfile vs copy_file_range vs splice, Measured
- Copying, Moving, and Splitting Files: Ten Measured Guides
Sources
- Linux man-pages, cp(1) — read 2026-11-10:
-ais the same as-dR --preserve=all;--preserve=allcovers mode, ownership, timestamps, links, context, and xattr. Box runs GNU coreutils 9.4; the manual text is coreutils 9.11 and every cited behavior was exercised by the probe itself. - rsync(1) manual — read 2026-11-10: a trailing slash on the source changes the behavior to avoid creating an additional directory level at the destination, and a trailing slash means copy the contents of this directory as opposed to copy the directory by name;
--no-whole-filedisables whole-file updating when it is enabled by default for a local transfer. Box runs rsync 3.2.7, protocol 31. - Linux man-pages, tar(1) — read 2026-11-10: ustar is the POSIX 1003.1-1988 format and posix is the POSIX 1003.1-2001 pax format;
-ccreates an archive and-xextracts one. Box runs GNU tar 1.35. The one-second mtime resolution is the probe's own finding, measured on all six tar-pipe tree reps across two nights. - CopyProgramming, How to Copy Folders and Contents in Linux — read 2026-11-10: publishes one unreplicated 10 GB table, cp -a 2 minutes 41 seconds against rsync -a 3 minutes 12 seconds, with no tar-pipe arm, one shape, no reps stated, and no output verification; asserts tar can be 8 times faster for millions of small files, citing one production scenario with parallelized tar, not a plain tar pipe. The closest published table, and the gap this probe fills.
- dar project, Benchmarking backup tools — read 2026-11-10: one unreplicated run on a full 4.1 GB Linux system install of 136,837 files reports cp 5.15 seconds, tar 8.04 seconds, rsync 16.59 seconds, and concludes cp is always fastest. A backup-oriented benchmark whose tar arm creates then extracts in two steps, not a pipe; it contradicts the tar claim above, and this probe adjudicates both by varying the corpus shape.
- DEV Community, Benchmarking 10GbE NAS-to-NAS Transfers — read 2026-11-10: November 2026, cp completes a single 15.17 GiB file over NFS at 479 to 494 MB/s against one rsync process at 181 MB/s. A network migration with no tar arm and no tree shape, a different job, and the same direction on the single-file shape.
- Veldica, rsync's 2,729x Speedup Is 1% Slower on the Clock: Delta vs Whole-File, Measured in Wall-Clock — the sibling guide: measures re-copying a changed file, delta against whole-file, not first-copy tree speed. This guide copies a tree for the first time; it does not re-copy a changed file.
- Veldica, mv Same Filesystem vs Cross-Filesystem, Measured — the sibling guide: measures moving a tree, rename against copy-plus-delete, not copying it. This guide copies; it does not move.
- Veldica, dd vs cp: Copying a 1 GiB File, Measured — the Block Size Is the Decision — the sibling guide: measures single-file copy by block size, not cp against rsync against tar on a tree. This guide asks which tool copies a tree fastest on first copy.
Keep Exploring
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.
Paste sshd -G output and get a hardening verdict on the values your server actually runs.
Paste a server block and get WebSocket, TLS, HSTS, and proxy-header verdicts.
Paste a systemd timer expression and get the specific reason it fails, the normalized form, and the past-date traps the built-in check hides.
The full sysadmin hub \u2014 systemd, cgroups, file tools, and measured Linux comparisons.