touch -r: copy timestamps from a reference file
Mirror another file's modification time onto a target file using touch -r on Linux.
01Command
$ touch -r reference.dat build/artifact.stamp02What 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
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- touch(1P) — POSIX manual pageEvidence: POSIX documents touch creating files when absent and updating access/modification times
- touch(1) — Arch Linux manualEvidence: -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
Find every occurrence of a pattern across all files in a tree, printed as file:line:number matches.
Unpack a gzipped tarball into the current directory while printing each file as it is extracted.
Show total, used, and available space plus usage percentage for every mounted filesystem in human-readable units.