How to show a timestamp in Bash history
By default, when you run the history
command, it lists the history of all commands previously executed, but it does not include a timestamp.
Adding a timestamp to the bash history can easily be accomplished with the HISTTIMEFORMAT
Bash variable as shown.
export HISTTIMEFORMAT="%F %T "
export PS1="\u@\h:$(pwd)> "
As an added bonus, I like the PS1
variable in the example above because it lists the username, hostname, and full path in a single line.
Here's an example of the output:
