touch -r: copy timestamps from a reference file

Mirror another file's modification time onto a target file using touch -r on Linux.

LinuxFilestimestamptouchLow risk
Run touch -r REFERENCE TARGET to set the target's access and modification times equal to the reference file's.

01Command

Command
$ touch -r reference.dat build/artifact.stamp

02What it does

The forgotten touch flag -r uses an existing file as the clock source instead of the current time. It is handy for making generated files appear as old as their source (reproducible builds, stamp files in make), and combining it with -c prevents touch from silently creating the target if it is missing. You can also set explicit times with -d or -t, but -r avoids parsing date formats entirely.

03Risk

RiskLow risk
!Warning: touch creates the target file if it does not exist; add -c when that would be a mistake.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • touch(1P) — POSIX manual page
    man7.org · technical · 2026-09-17
    Evidence: POSIX documents touch creating files when absent and updating access/modification times
  • touch(1) — Arch Linux manual
    Arch Linux · technical · 2026-09-17
    Evidence: -r, --reference=FILE: use this file's times instead of current time; -c do not create missing files

Last verified: 2026-09-17 · Category: Files & Folders

06Related solutions