Back Up a File with Today's Date in the Name

Make an instant timestamped copy before touching an important file.

macOSbackupFilesLow risk
Run cp with $(date +%Y%m%d) inside the destination name to stamp the backup with today's date.

01Command

Command
$ cp ~/Documents/config.txt ~/Documents/config-$(date +%Y%m%d).txt

02What it does

date +%Y%m%d expands to 20260917-style text right inside the command, so each day's backup gets a unique name and never overwrites yesterday's. Add -p to preserve the original timestamps, or swap the format to +%Y%m%d-%H%M if you back the same file up several times a day. This is the one-line habit that replaces "copy of config-FINAL-v2.txt".

03Risk

RiskLow risk
!Warning: Two backups in the same second are not possible with %H%M granularity — rename manually if you need sub-minute versions.

04Undo

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

05Sources

  • cp – Copy files
    ss64.com · technical · 2026-09-17
    Evidence: cp copies a file; command substitution $(date +%Y%m%d) stamps the copy with the current date.

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

06Related solutions