How to add date and time to bash history

Have you ever run the command “history” in bash and notice how inadequate that seems by default? You have no idea what date or time a particular command is ran. This makes troubleshooting difficult especially if you are trying to track where certain things go wrong.

To correct this, you can simply add this line to your bash configuration. If you wish to make this system wide and implement for all users:

echo "export HISTTIMEFORMAT='%F %X '" >> /etc/bashrc

If you wish to only implement it for the currently logged in user:

echo "export HISTTIMEFORMAT='%F %X '" >> ~/.bash_profile

There’s lots of ways you can customize your shell to be more useful to you, and this should whet your appetite and get you started.