Command line

mv Across Filesystems, Measured: One Rename or a Full Copy

The same mv command moves a 1 GiB file in 0.002 seconds or in about 1 second, depending on one thing: whether the source and the destination are on the same filesystem. On one filesystem it is a single rename. Across filesystems it is a copy followed by a delete, and a 10,000-file tree costs the same as the file.

Written November 9, 2026 · 10 min read

By the end of this guide
  • The table: 0.002 seconds on one filesystem, about 1 second across
  • Why the same command is two operations
  • mv cross-filesystem is cp plus rm, and the numbers agree
  • The tree costs the same as the file — and the banking night got this wrong

What this guide is

One command, two filesystems, six arms, three reps each. The file is 1 GiB of random bytes; the tree is 10,000 files of 1 KiB. The source lives on tmpfs (/dev/shm, device 65) and the destination on ext4 (the home directory, device 2096), so the cross-filesystem arms really do cross a filesystem boundary — the probe checks the device numbers rather than assuming it. Every arm's output is verified byte-for-byte against the master file with cmp, and every file move records its mode and modification time before and after, so the table compares moves that arrived intact.

The question is the one people ask when a move takes forever: why did mv finish instantly yesterday and take a second — or a minute — today. The answer is that mv is two different operations wearing one name, and which one runs depends on the filesystems, not on the file. The table below puts numbers on both, on two separate nights, and the two nights disagree in one instructive place.

The table: 0.002 seconds on one filesystem, about 1 second across

Wall seconds, medians of three runs, fresh tonight.

  • mv same filesystem, 1 GiB file: fresh median 0.0024, reps 0.0024, 0.0025, 0.0022. Night before: 0.0026, reps 0.0024, 0.0026, 0.0435.
  • mv cross-filesystem, tmpfs to ext4, 1 GiB file: fresh median 1.046, reps 1.046, 8.954, 1.033. Night before: 0.789, reps 0.772, 0.789, 1.182.
  • cp plus rm cross-filesystem, 1 GiB file: fresh median 0.797, reps 0.436, 0.847, 0.797. Night before: 0.885, reps 0.866, 0.885, 0.971.
  • mv cross-filesystem, reverse direction, ext4 to tmpfs, 1 GiB file: fresh median 0.768, reps 0.436, 0.792, 0.768. Night before: 0.814, reps 0.436, 0.814, 1.015.
  • mv tree, same filesystem, 10,000 files of 1 KiB: fresh median 0.0022, reps 0.0022, 0.0022, 0.0022. Night before: 0.0025, reps 0.0022, 0.0025, 0.0025.
  • mv tree, cross-filesystem, 10,000 files of 1 KiB: fresh median 0.868, reps 1.014, 0.794, 0.868. Night before: 1.077, reps 0.873, 1.077, 1.205.

The 0.002-second cells are at the spawn floor — the cost of starting the mv process itself — so this guide never divides by them. The honest statement is absolute: the same move costs about two milliseconds on one filesystem and about a second across filesystems, for the same 1 GiB file and for the same 10,000-file tree. The size of the data does not matter on one filesystem, because no data moves.

Why the same command is two operations

On one filesystem, mv calls rename(2). The manual says rename moves a file between directories if required, and that old and new path must be on the same mounted filesystem — otherwise it fails with EXDEV. The rename updates directory entries; the bytes stay where they are, which is why a 1 GiB file and a 10,000-file tree both take about two milliseconds. The GNU coreutils manual adds the other half: when renaming does not work because the destination's filesystem differs, mv falls back on copying as if by cp -a, then removes the original. That fallback is the whole cross-filesystem column of the table.

The fallback also explains the non-atomicity that the copyprogramming guide states and this probe did not test: a cross-filesystem move is a copy followed by a delete, so a crash mid-copy leaves a partial destination and the original still in place, and the manual says mv removes the partial copy if the copy fails. The probe ran no mid-copy kill test, and this guide claims no result from one — the non-atomicity is mechanism, documented in the manual, not a measurement here.

mv cross-filesystem is cp plus rm, and the numbers agree

The claim this probe was built to test is the copyprogramming guide's: on a 10 GB mixed directory, cp -a took 2 minutes 41 seconds and mv across filesystems took 2 minutes 43 seconds, and the guide concludes mv offers no performance advantage when crossing filesystems. That table has one run, no reps, no same-filesystem arm, and no tree arm.

Tonight mv cross-filesystem took 1.046 seconds at the median against 0.797 for cp plus rm; the night before it was 0.789 against 0.885. The two arms swap places between nights, and their ranges overlap on both nights, so there is no winner to report — only that both cost about a second for a gigabyte, and the direction does not matter either (0.768 reverse tonight, 0.814 the night before). The mechanism agrees: mv across filesystems copies as if by cp -a and then deletes, so it should cost what a copy costs, and it does.

Two cells deserve a sentence each, not a footnote. The cross-filesystem mv arm spiked to 8.954 seconds on its second rep tonight — eight times the other two reps — while the night before its worst rep was 1.182. Nothing in the probe explains the spike; it is the same class of scheduler and I/O noise that landed on different arms on different nights in the sibling guides, and it is why the guide prints ranges, never medians alone. And the first rep of both the cp arm and the reverse mv arm landed at 0.436 seconds tonight, roughly half the other reps — the page cache was warm from the arm before it, and the first copy of the night got the benefit. A median of three with a fast first rep and a slow spike is a different claim from a median of three tight reps, and the table shows which is which.

The tree costs the same as the file — and the banking night got this wrong

The banking night's note said the 10,000-file tree costs more than the 1 GiB file across filesystems: 1.077 seconds against 0.789, because per-file open, copy, and close dominates. Tonight the ordering flipped: the tree took 0.868 against the file's 1.046. The tree's own numbers barely moved between nights (1.077 to 0.868, ranges overlapping); the file arm moved up. The per-file-overhead reading was an artifact of one fast night for the file arm, not a property of trees, and this guide corrects it rather than repeating it: across filesystems, a 10 MB tree of 10,000 files and a 1 GiB single file cost the same order of time, about a second, on both nights. The finding that survives both nights is the same-filesystem one — the tree is still a single rename at 0.0022 seconds, because moving a directory renames the directory, not its ten thousand files.

The metadata trap: mv preserves the timestamp, plain cp does not

Trap
Every file move in the probe recorded mode and modification time before and after. mv preserved both exactly on all nine file reps across both directions: permissions 664 and the modification time unchanged to the second, on every rep, on both nights. That is the cp -a fallback doing what the manual promises — cp -a preserves attributes, and mv across filesystems uses it.

Plain cp does not. On tonight's three reps, the copied file's modification time advanced by one second on two reps and landed in the same second on the first, so the destination looked unchanged on that rep by luck of the clock. The banking night showed the same shape: two reps advanced, one landed in the same second. The rule is that cp stamps the copy with the time it was written, and the same-second landing is a coincidence of a one-second clock, not preservation. Anyone moving files across filesystems and then sorting by modification time — a backup script, a make build, a photo import — gets the original timestamps from mv and the copy time from cp, and the difference is silent: the file contents are identical, cmp passes, and only the timestamp tells the story.

How to tell which side of the cliff you are on

Before moving a large file, check whether the source and the destination are on the same filesystem. The device number is the test: stat -c %d prints the device holding each path, and different numbers mean different filesystems. /dev/shm reports 65 and the home directory reports 2096. df shows the same split in its source column — none mounted on /dev/shm, a real disk on /. If the numbers differ, the move will copy every byte; if they match, it will be a rename. A move between two directories on the same disk can still cross filesystems — separate partitions, a tmpfs mount, a USB stick — so the check is the device number, not the drive.

Checklist

  • Before moving a large file, check the device numbers with stat -c %d on the source and the destination — different numbers mean the move copies every byte.
  • Before assuming a move is instant, check the filesystem, not the disk — two directories on one disk can still be different filesystems.
  • Before quoting a ratio, check the range: the cross-filesystem arm spiked to 8.954 seconds on one rep tonight, so its median of 1.046 is not the whole story.
  • Before choosing between mv and cp plus rm across filesystems, check the table: the two swap places between nights and their ranges overlap, so neither is consistently faster.
  • Before trusting a copied file's timestamp, check how it got there — mv preserves the modification time across filesystems, plain cp stamps the copy time, and a same-second landing can hide the difference.
  • Before reusing these numbers, check the setup: WSL2, 32 CPUs, GNU coreutils 9.4, tmpfs to ext4, warm page cache, one thread per arm — the ranking held across two nights, the absolute seconds are this box's.

Sources

  • rename(2), Linux manual page — read 2026-11-09: rename moves a file between directories if required; old and new path must be on the same mounted filesystem, otherwise it fails with EXDEV; if the new path exists it is atomically replaced.
  • GNU Coreutils, mv invocation — read 2026-11-09: mv ordinarily simply renames; when renaming does not work because the destination's filesystem differs, it falls back on copying as if by cp -a, then removes the original; if the copy fails it removes any partially created copy. Box runs coreutils 9.4; the manual text is 9.11, and every cited behavior was exercised by the probe itself.
  • copyprogramming, How to Move Files in Linux Terminal — read 2026-11-09: the nearest published table — one run, no reps, on a 10 GB mixed directory on ext4: cp -a 2 minutes 41 seconds, mv cross-filesystem 2 minutes 43 seconds, rsync -a 3 minutes 12 seconds; concludes mv offers no performance advantage when crossing filesystems; states the same-filesystem move is atomic and the cross-filesystem move is copy plus delete and non-atomic. This guide's table is the same question on one shared corpus, three reps per arm, with a same-filesystem control arm, tree arms, and verified-equal outputs.
  • Veldica, dd vs cp: File Copy Block Size, Measured — the sibling guide: the same tmpfs and warm-cache harness, different question — copying versus moving. Its block-size trap is the same failure shape as this guide's metadata trap, a silent difference in a file that cmp says is identical.

Keep Exploring