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.
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 ~/.bashrc02What 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
!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 ~/.bashrc05Sources
- strftime(3) — Linux manual pageEvidence: Reference for the format specifiers usable in HISTTIMEFORMAT, such as %F for the date and %T for 24-hour time.
- bash(1) — Linux manual pageEvidence: 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