Set Date and Time for Each Command You Execute in Bash History

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.95/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

12 Responses

  1. mohammad says:

    Hello,
    Thanks million for your efforts and your great post.
    I want to show ip address (of the user that executed the command) in history command. How can i do that?

    Second question
    when i ssh to my linux machine with putty and suddenly my windows restart (for any reason) there is no history in next ssh
    but if i exit from putty with command “exit” in my server history will be saved for next ssh login.
    how can i set that each command to be saved even if putty closed abnormal?

  2. Alexey says:

    Thank you!

  3. Marek says:

    Modifying bash_history file won’t let you use other options, like re-running some command from history by using ! char at the beginning. IMHO, good, but not ideal

    • Nick says:

      Marek, I have this line: export HISTTIMEFORMAT=”%Y-%m-%d %T ”
      in my ~/.bash_profile and all works as expected. I can use !!

    • Aaron Kili says:

      @Marek

      You actually do not have to modify the bash_history file. This method simply adds the timestamp to a command entry in it, and you can re-run commands as usual.

  4. ThisHosting.Rocks says:

    Just don’t forget to update your actual system time to correlate with your IRL time. Usually the system’s (server) time is not the same as the one where you’re actually working from.

    It’s just easier, not that it really matters.

  5. Faissal says:

    Great!
    It’s nice to add a space or tab between the date and its command :)

    Thanks.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *