Add time and date to your bash history

Rob —  June 10, 2013 — 4 Comments

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 (or /etc/bash.bashrc in ubuntu)
Per user: edit ~/.bashrc

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

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

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:

See:

Let me know how it works out for you!

Related posts from Linux Brigade!

  • Bash ShellShock bug – Find out if you’ve been “tested”Bash ShellShock bug – Find out if you’ve been “tested” We’ve seen the articles about how to find out if you’re vulnerable to the bash shellshock bug, we’ve also seen the articles on how to patch your system.  What I’ll show you is how to find […]
  • Send mail via the command lineSend mail via the command line During your stint as a Linux administrator, you’ll likely want to send mail from the server you are working on. Whether its sending a quick test message or emailing yourself a file, it can […]
  • Delete cPanel account error_log filesDelete cPanel account error_log files If you have a large number of accounts on your server, you may also be wasting a lot of space with the error_log files in each account. Some can get very large – and while you want to […]
  • cPanel server – can’t send mail! If you are trying to send mail via webmail and it is not working out, you may have the answer right under your nose.  If you have CSF installed, it is likely blocking port 25.

    You may […]

  • Can’t afford a full time Linux admin?Can’t afford a full time Linux admin? If you’re just starting out, it’s tough being able to afford full time Linux support.  Why not employ Hosting Support Services instead?  We’re Red Hat certified, fluent with Red […]

4 responses to Add time and date to your bash history

  1. Dude! You’ve got some seriously helpful information going on here. I’ve already bookmarked your site, and now I’m starting a reference notebook with the posts that I’ve printed off. Thanks for saving me a bunch of time & headache.

  2. I think this will be very handy when I need it. I wish I would known about this sooner, it would have saved me a lot of time. Thanks for the detailed guide as always, much appreciated.

  3. Wow, that would have come in handy more times that I would like to admit! I would never have thought to check into adding time-stamps like that. You’ve inspired me to dig further into learning the in’s and out’s of bash.

  4. This is another great tip. Sometimes I’ll have a really important command that I haven’t used in a week or two, and it just disappears into the history. This is a great way to keep older commands without having to make a text file to contain all of them. Also I believe for certain command line interpreters there’s a GUI option to set the BASH history.

Leave a Reply to Sly14Cat Cancel reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url=""> 

*