The history command shows us in the terminal the commands that we have executed in the past, something like this:
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:
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
Nice 🙂
Better, impossible.
The copy-paste version in terminal.
echo "export HISTTIMEFORMAT = '% F% T:'" >> ~ / .bashrc; source ~ / .bashrc
Tadaaan ...
Uff don't try that, wordpress quotes don't work in terminal.
Enclose the code between (code) …… (/ code)… BUT, changing the parentheses for less-than and greater-than signs
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
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 😀
Ahh goes. I understand
Thanks for the answer and then to save it in the .bashrc.
😀 Greetings
Not at all, thanks to you for commenting 🙂
Cool.
That's the idea 😀
Great !, simple and effective. Thank you.
Thank you
Excellent Tip !, many days of these 🙂
Very good contribution, it works perfect, thanks.
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.
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 ???
It does not work, it takes the current system date and not the command execution date
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.
A question KZKG ^ Gaara.
You can also show the users who executed the commands?
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.
Excellent, thanks for the contribution it has been of great help.
regards
I need to make a script that exports the history to me and doing it through bash does not take it.
Help