Verified accountThis account is verified. Learn more
@fswlinux
A practical guide to becoming a confident Linux user and sysadmin. Linux tips, insights, and lessons from the book. Get the book at firststepswithlinux.com
You can enable timestamps in your bash command history to see when you ran previous commands. This can be useful for tracing what you were working on and when.
To add timestamps to your history, just set the HISTTIMEFORMAT environment variable like so:
$ export HISTTIMEFORMAT="%F %T "
Now when you view your history or grep through it, you'll see a timestamp next to each command indicating when it was run:
$ history | tail -n 5 Or to save a couple of keystrokes:
$ history 5
The format "%F %T" shows the date and time, but you can customize it to your liking.
Note: This does not put historical timestamps on commands you executed before setting HISTTIMEFORMAT.