Add Timestamps to bash History

By chimo on (updated on )

It turns out it's pretty easy to add timestamps to bash's `history` shell built-in. Add the following in your .bashrc:

HISTTIMEFORMAT="%F %T "

Reference.

This turns a bash history from something like:

1 cd ~/devel
2 ls
3 rm -r old/

To something like:

1 2024-11-25 16:56:06 vi .bashrc
2 2024-11-25 16:56:15 source .bashrc
3 2024-11-25 16:56:17 history

It's something I had wondered about in the past, but never bothered looking it up. Unfortunately, I don't think there's an equivalent for busybox's `ash` shell history, but I don't mind too much. I enabled this at work though, where I use Debian under WSL.