History command with execution dates of each command

The history command shows us in the terminal the commands that we have executed in the past, something like this:

history-command-output
So far so good, but what if we want to know exactly when we executed each command in the past? O_O

I mean, see something like this:

history-command-output-date

To do this, we must put this command in the terminal:

export HISTTIMEFORMAT='%F %T : '

Then they run again history and see the result 🙂

Now, what we just did will not be permanent, that is, when we close the session (or turn off the computer) this cool way of seeing the output of the history command will be forgotten by the system, to make it permanent we must run the following:

echo "export HISTTIMEFORMAT='%F %T : '" >> $HOME/.bashrc

That is, put that command at the end of our file .bashrc that is hidden in our home.

By the way, for those who wonder what does% F and% T mean…% F means the date in year-month-day mode, while% T is the time in hour-minute-second mode (24-hour time ).

Well I don't think there is anything else to say, it is a fairly short post but I think the tip is interesting ^ - ^

regards


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

23 comments, leave yours

Leave a Comment

Your email address will not be published.

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   elav said

    Nice 🙂

  2.   eliotime3000 said

    Better, impossible.

  3.   dhunter said

    The copy-paste version in terminal.

    echo "export HISTTIMEFORMAT = '% F% T:'" >> ~ / .bashrc; source ~ / .bashrc

    Tadaaan ...

    1.    dhunter said

      Uff don't try that, wordpress quotes don't work in terminal.

      1.    KZKG ^ Gaara said

        Enclose the code between (code) …… (/ code)… BUT, changing the parentheses for less-than and greater-than signs

  4.   ermimetal said

    Thanks for the KZKG ^ Gaara data but there is a detail:
    The date is always today's date, not really the date when the command was run.
    Or at least that came out in my tests. Cheers

    1.    KZKG ^ Gaara said

      It seems that it only works well with commands that have been executed after the export has been done, that is, tomorrow you will see that the commands that you execute tomorrow will be fine, and etc etc as the days go by.

      You understand? 🙂

      Thanks for the comment 😀

      1.    ermimetal said

        Ahh goes. I understand
        Thanks for the answer and then to save it in the .bashrc.

        😀 Greetings

        1.    KZKG ^ Gaara said

          Not at all, thanks to you for commenting 🙂

  5.   Julian said

    Great !, simple and effective. Thank you.

    1.    KZKG ^ Gaara said

      Thank you

  6.   pepE (@valdezpepe) said

    Excellent Tip !, many days of these 🙂

  7.   Blazek said

    Very good contribution, it works perfect, thanks.

  8.   taregon said

    Interesting info !! At first I thought it did not work, because the previous commands appeared with the same date; but those that he was introducing, those if he indicated the correct time.

  9.   khepeshef said

    Hello

    Super useful tip ,, only that I had a problem giving the commands as you indicate the export HISTTIMEFORMAT = '% F% T:' and then the history ... if it sends me the date and time of all the commands ,, the strange thing is that I It sends in all the commands it sends me the date and time that the computer has at that moment, that is, it does not show me the real date and time of the commands ,,,, I get commands that I gave yesterday but it sends me the current computer date…. So it doesn't work for me because I'm not seeing the real date.

    How could I save the actual dates ???

  10.   Ringmaster said

    It does not work, it takes the current system date and not the command execution date

    1.    KZKG ^ Gaara said

      When you format it to put the date on it, the commands you executed BEFORE this will not have the correct date, however those you execute afterwards will.

  11.   roucat said

    A question KZKG ^ Gaara.
    You can also show the users who executed the commands?

    1.    John James said

      The history is particular to each user, so that you would have to enter the session of each user to validate what you need, now if you want something with greater control I recommend the use of SUDO, since that if it leaves a record of everything executed for each user with dates and others.

  12.   Juan Carlos said

    Excellent, thanks for the contribution it has been of great help.

    regards

  13.   Cosme said

    I need to make a script that exports the history to me and doing it through bash does not take it.

    Help