Madhav Kobal's Blog

This blog will be dedicated to Linux, Open Source and Technology news, affairs, how-tos and virtually EVERYTHING in these domains.

Add time And Date To Your Bash History

Posted by madhavkobal on 20/08/2009

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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: