Add date-time info to history output in Linux

By default you dont have date-time information in output from command “history” in terminal but you can set that by using one variable in .bash_profile or profile file. Unfortunately this cannot be used for already recorded commands in history – they will have date-time info but it will be hard-coded to date-time when you set-up variable and not to real time when commands were executed.

# Set permamanent date-time output in history (it will be lost after log off)

# Set date-time info by default after your next login
echo "export HISTTIMEFORMAT='%F %T: '" >> ~/.bash_profile

# Set date-time info by default for all bash users in Linux
su - root # If you are not logged in as root only
echo "export HISTTIMEFORMAT='%F %T: '" >> /etc/profile

Here is a sample “Before and After”

As you see, much better option for you is to have this information – always.