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 […]
  • Change main hostname and IP of WHM/cPanel machineChange main hostname and IP of WHM/cPanel machine One thing you’ll probably run into sometime is changing the hostname and IP address of a cPanel machine.. whether you’re cloning it for a quick start or if you’ve taken it over.. moving it […]
  • Block Countries using mod_geoip in cPanel Yesterday, I wrote an article on how to block certain countries from your server using csf. This will block them from accessing your server on any port. You can, however use mod_geoip if […]
  • Turn off unneeded services on your Linux machineTurn off unneeded services on your Linux machine One of the easiest ways to start securing your server (and speeding it up) is to turn off unnecessary services that are usually running by default. This little script will go through and […]
  • Lock down your SSH port/accessLock down your SSH port/access The instant a Linux server is connected to a public network it starts getting hit by attackers. There are people out there running programs constantly against IP ranges and they’ve hit […]

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

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

*