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 […]
  • Migrate CXS license from one server to anotherMigrate CXS license from one server to another When you upgrade servers, you usually like to take things you paid for with you to your new one. This will show you how.

    So you want to migrate CXS license from one server to […]

  • Block account from sending mail WHM/cPanelBlock account from sending mail WHM/cPanel There may come a time when you’d like to block an account / domain on your WHM/cPanel server from being able to send mail. Here’s how you’d get it done!

    We’re going to set up a […]

  • 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 […]
  • Import MySQL database from command lineImport MySQL database from command line You’ll need to import a database via command line from time to time – I’ll normally opt for this anyway. After seeing how easy it is, you’ll probably end up using the command line instead […]

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 ohyesuare 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=""> 

*