Today I Learned - Zsh History Timestamps
A short DFIR 'Today I Learned' post explaining that Zsh keeps in-session command history with timestamps accessible via `fc -lf` or `fc -li 100`, unlike the on-disk ~/.zsh_history file which loses per-command timestamps after reboot. The author recommends analysts capture this during live response and suggests configuring HISTTIMEFORMAT permanently to preserve timestamps for future investigations. Relevant to incident responders working on macOS (default shell since Catalina), Kali Linux, and Gentoo systems.
What it is
A DFIR note on Zsh command-history timestamps and how they behave differently on a live session versus after the history is flushed to disk. Zsh is the default shell on Kali, Gentoo, and macOS (since Catalina). The practical payload beyond the summary is the full set of fc timestamp flags and their output formats.
How it works
During an active session Zsh holds each command in memory alongside a timestamp of its actual execution time, viewable with fc. Once the session closes or the box reboots, the entries persisted to ~/.zsh_history lose those per-command execution times — in the author's limited testing the timestamps collapsed to what looked like the session-open time. So a live-system pull can yield accurate per-command timing that a dead-box acquisition of ~/.zsh_history cannot.
What to do
On a live system, dump history with timestamps before the session ends:
fc -lf
fc -li 100The fc built-in exposes several timestamp formats (from the zshbuiltins man page) — pick per investigation:
-d— prints timestamps for each command-f— full date-time, USMM/DD/YY hh:mmformat-E— full date-time, Europeandd.mm.yyyy hh:mmformat-i— full date-time, ISO8601yyyy-mm-dd hh:mmformat-D— elapsed times; combinable with one of the above
For future readiness, make timestamping persistent by setting HISTTIMEFORMAT in the shell profile.
Caveats
- The reset-to-session-open behavior is the author's observation from "limited testing," not a documented guarantee — treat on-disk
~/.zsh_historytimestamps as unreliable rather than assuming a specific fallback value. - The timeline-reconstruction value only exists while the session is live; capture history before logout/reboot or you lose per-command timing.
- The page recommends
HISTTIMEFORMATfor Zsh, but note this is conventionally the Bash timestamp variable; verify the correct persistence mechanism for your target shell before relying on it.
Technologies named here
- fc
- Kali
- zsh_history file
- Gentoo
- macOS
- Zsh
- Kali Linux
Related in Blue Team & Detection
AI-Coded Malware | Analyzing Vibe-Coded AD Enumeration | Huntress
