Copy a file with today's date in the name

Make a timestamped backup copy before editing a config or document.

LinuxbackupcopytimestampsLow risk
Run cp -a file "file-$(date +%F).bak" to create a dated backup copy next to the original.

01Command

Command
$ cp -a nginx.conf "nginx.conf-$(date +%F).bak"

02What it does

Command substitution $(date +%F) expands to today's date in YYYY-MM-DD form, so each backup lands in its own uniquely named file instead of overwriting yesterday's copy. The -a flag preserves permissions, ownership, and timestamps, which matters for config files. Run it again on another day and you get a second, separate backup.

03Risk

RiskLow risk
!Warning: If you run this twice in the same shell script, the filename only changes once per day — add %T for the time (file-$(date +%F-%H%M)) if you need several backups per day.

04Undo

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

05Sources

  • date(1) — Linux manual page
    man7.org · community · 2026-09-17
    Evidence: date +%F prints the current date as YYYY-MM-DD; command substitution $( ) embeds it into the destination filename.

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

06Related solutions