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 […]
  • Understanding cron job timesUnderstanding cron job times Often, you’ll want to use cron to schedule daily, weekly, hourly (etc…) tasks on your linux system(s). cPanel has a little GUI for it, but since I don’t trust GUIs very often, I like […]
  • Globally disable directory listing on WHM/cPanelGlobally disable directory listing on WHM/cPanel One of the things that WHM/cPanel servers have on by default is directory listing. This is something you don’t want – but it’s easy to fix!

    1. Log into WHM
    2. Apache Configuration […]

  • Block Countries from your server easily with CSFBlock Countries from your server easily with CSF If you don’t have a need for certain international visitors to your Linux server, its easy to block them out!  First, you’ll need to make sure that CSF is installed.  You can follow our […]
  • 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 Yrex 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=""> 

*