Show Timestamps in Bash History (HISTTIMEFORMAT)

Make `history` print the date and time each command was executed by setting the HISTTIMEFORMAT variable in your shell config.

LinuxbashshellclihistoryLow risk
Add export HISTTIMEFORMAT="%F %T " to ~/.bashrc and reload it — then history shows a date and time beside every entry.

01Command

Command
$ echo 'export HISTTIMEFORMAT="%F %T  "' >> ~/.bashrc && source ~/.bashrc

02What it does

Bash already stores a timestamp for each history entry internally; HISTTIMEFORMAT just tells it to display one using strftime codes — %F is the date, %T the 24-hour time. The timestamps apply to new commands as you run them; older entries saved before you set the variable share one import time, so give the setting a session to accumulate real data. It also survives into scripts that source your environment and works with grep on history output for quick 'when did I run X' lookups.

03Risk

RiskLow risk
!Warning: History timestamps are only as trustworthy as the machine clock, and existing entries won't retroactively gain correct times — only commands run after the change get real timestamps.

04Undo

Undo
$ Remove the HISTTIMEFORMAT line from ~/.bashrc

05Sources

  • strftime(3) — Linux manual page
    man7.org · community · 2026-09-17
    Evidence: Reference for the format specifiers usable in HISTTIMEFORMAT, such as %F for the date and %T for 24-hour time.
  • bash(1) — Linux manual page
    Arch Linux · community · 2026-09-17
    Evidence: Documents HISTTIMEFORMAT: if set, its strftime format is used to display (and store) timestamps for each history entry.

Last verified: 2026-09-18 · Category: Developer