Save Bash History With Timestamps

To check all the commands executed we can simply run history command. This will give us a nice long out put of the all commands executed via bash.

history

bundle install -j  4
gem install passenger
sudo service apache2 restart
passenger-install-apache2-module
sudo subl /etc/apache2/apache2.conf
sudo service apache2 restart
sudo a2ensite codesapling.conf
sudo service apache2 restart
rails s

But at critical times we might need to check the timestamps along with the commands executed on main server machine. To help that we can simply add a variable HISTTIMEFORMAT to bashrc

echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile ; bash

This will add a setting and reload your current bash. Now you can check your history along with time stamps.

history

19.07.14 11:34:19 echo 'export HISTTIMEFORMAT="%d.%m.%y %T "' >> ~/.bashrc
19.07.14 11:36:19 history
19.07.14 11:38:02 bash
19.07.14 11:38:22 history
19.07.14 11:39:08 ls
19.07.14 11:39:16 git add .
19.07.14 11:39:22 git push origin master
19.07.14 11:39:34 history

Comments