Howto Add time And Date To Your Bash History

Wed, Aug 12, 2009

Linux

This comes in very handy if your trying to track back when you had last run something.
To enable it just simply add export HISTTIMEFORMAT="%h/%d - %H:%M:%S " to your .bashrc file

echo 'export HISTTIMEFORMAT="%h/%d - %H:%M:%S "' >> ~/.bashrc

Then reload your .bashrc

source ~/.bashrc

Now when you run history you should get a output similar to the one below

   502  Aug/12 - 13:48:31 tail -f /home/duffy/log/access.log
  503  Aug/12 - 13:49:01 echo hello
  504  Aug/12 - 13:49:24 more /var/log/syslog

Some other bash history tips

  1. The best way of finding something quickly in your bash history is simply by pressing ctrl+r and then typing out the start of the command it will auto complete it with any matches found in your bash history
  2. If you don't want to save duplicate commands in your bash history simply add export HISTCONTROL=ignoreboth to your .bashrc
    echo 'export HISTCONTROL=ignoreboth' >> ~/.bashrc
  3. If you want to change the lenght of history add export HISTSIZE=1000 to your .bashrc
    echo 'export HISTSIZE=1000' >> ~/.bashrc
, , , , , , , ,

This post was written by:

- who has written 47 posts on Tuts4Tech.

I am the owner of this website, please feel free to ask me any questions you have

Contact the author

Leave a Reply