Show Timestamps in Bash History

The default Bash history is fine. But when you’re trying to remember when you ran a command or debug a past session, t’s basically useless.
Here’s how to fix that.
Add Timestamps to Your Bash History
Append this line to your ~/.bashrc
:
HISTTIMEFORMAT="%b-%d-%Y %T "
Then reload:
source ~/.bashrc
Now when you run history
, you’ll see this instead of just a wall of commands:
421 Jul-22-2025 10:12:33 sudo apt update
422 Jul-22-2025 10:12:50 sudo apt upgrade
423 Jul-22-2025 10:13:02 ./battery_level.py -c
Way more helpful.
Format Breakdown
%b - abbreviated month (e.g., Jul)
%d - day of month
%Y - full year
%T - time (HH:MM:SS)
You can tweak the format to whatever you like. If you prefer slashes or numeric dates:
HISTTIMEFORMAT="%m/%d/%y %T "
Why It Matters
Know exactly when you ran a specific command
Troubleshoot system issues by timeline
Reconstruct sessions after a reboot or crash
Just a better mental model of your workflow
Bonus Tip: View a Timestamped History of a Specific Command
history | grep rsync
Now you’ll know when you ran that rsync
that corrupted your files, not just that you ran it.
Little shell upgrades like this make a big difference
Subscribe to my newsletter
Read articles from Roy Hayden directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
