Varyable’s Blog

March 19, 2009

Time-stamp your bash history

Filed under: linux — varyable @ 6:58 am

It’s often the case that we want to review our command history to look for certain erroneous or useful commands. We can do this using history command or just looking at the contents of ~/.bash_history file. Sometimes that’s not enough, and we want to know the exact time certain command was executed (think of systems with much longer up-times). Well, if we define HISTTIMEFORMAT environment variable our shell starts time-stamping our commands. This variable should be assigned a string that follows time format specification similar to the date command, except for the preceding ‘+’ of course. For example:


The time-stamps would only be reliable for any future commands, as older commands weren’t tracked by the shell. ~/.bash_history file would also look different now, as bash would be inserting a Unix Epoch value before each command.

Here goes a sample screenshot.

2nd & 3rd rows show our time-stamps

2nd & 3rd rows show our time-stamps


1 Comment »

  1. Thanks for this useful tip.

    However, I’d like to mention that your blog software is breaking your command line by replacing the quote characters (“) with bird droppings… This way, it can’t be used as is (by copy-pasting). Please fix this.

    Comment by AK — September 19, 2011 @ 11:46 am

RSS feed for comments on this post. TrackBack URI

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Create a free website or blog at

%d bloggers like this: