Articles Comments

LinuxOS Pro » General Linux » Add date, time to your bash history and increase it to 5,000 lines

Add date, time to your bash history and increase it to 5,000 lines

Often, you’ll go looking for a shell command that you used in the past – you can remember around when you did it but of course that won’t help you because by default the bash history won’t show you dates/times.  Here is an easy way to remedy that.  It won’t go into the past and give you dates, but from this point forward you’ll know when commands were executed.
 There are two ways to do this: globally or per user

Globally: edit /etc/bashrc
Per user: edit ~/.bashrc

Add this to the bottom of the file to add date/time:

export HISTTIMEFORMAT="%h %d %H:%M:%S "

Now, when you type history, it will show this:

340 Jan 20 08:26:40 cd /etc/
341 Jan 20 08:30:07 ls -l|grep conf
342 Jan 20 08:35:22 cp resolv.conf resolv.conf.bak
343 Jan 20 08:35:43 vim resolv.conf

Now let’s say that you want more history to be kept – by default it’s set to 500 lines. Add this to the bottom to increase it to 5000 lines:

HISTSIZE=5000

Let me know how it works out for you!

Filed under: General Linux · Tags:

One Response to "Add date, time to your bash history and increase it to 5,000 lines"

  1. mike says:

    make sure you type “bash” to ‘renew’ it, or the new history won’t show uup!

Leave a Reply

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tundra Forum