How to get the timestamp of a command in history?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #1

    How to get the timestamp of a command in history?

    Hey guys,

    An idea just came to my head. I ran some command on my host sometime in early January.

    Is there a way to find out when exactly that command was run WITHOUT looking at secondary evidences (such as the timestamp of a file that command may have produced).

    For example if I run ls, find, or grep and they exist in my command history. Is there a way, with a standard debian linux install, to find when that command was run?

    I'm assuming the answer is a big fat 'NO', but I'm curious anyway.

    :)

    Cheers!


    Dan
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    If you want it going forward you can modify the log format to do so.

    If the command is still running you can check the options of process information commands (things like ps, etc...)

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      ls,find,cat don't log by themselves.

      Going forward I could just type 'date' before and after each command :) Going back through your history, you know when you ran what.

      DM

      Comment

      • tgmerritt
        New Member
        • Aug 2011
        • 1

        #4
        You cannot go back and get timestamps of commands that were already run, but you can add the following to your bash_profile in order to have history timestamp things going forward:

        export HISTTIMEFORMAT= "%F %T "

        And then of course on your next login this will be exported.

        You'll get output like this:

        999 2011-08-24 10:12:02 vi .bash_profile

        Comment

        Working...