Linux command history with date and time

I want to test my Linux system when which command was run, what day and time.

I ran the commands as follows:

history 50 

It shows me the last 50 commands, but not with the date and time when it was launched. Does anyone know how to do this?

+8
linux history
source share
4 answers

regarding this link, another way out of the fisrt solution provided by krzyk ,

 echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile source ~/.bash_profile 

and it is a permanent way.

+7
source share

Try the following:

 > HISTTIMEFORMAT="%d/%m/%y %T " > history 

You can customize the format to your liking, of course.

+6
source share

It depends on the shell (and its configuration) in standard bash, only the command is saved without a date and time (check .bash_history if there is a timestamp there).

In order for bash to save the timestamp, you need to set HISTTIMEFORMAT before executing the commands, for example. in .bashrc or .bash_profile . This will cause bash to save timestamps in .bash_history (see Entries beginning with # ).

+2
source share
 HISTTIMEFORMAT="%d/%m/%y %H:%M " 

For any commands entered before this, this will not help, as they will simply get the default time when you turned on the history, but after that it will record the time of any subsequent commands.

If you want it to record history permanently, you should put the following in your ~/.bashrc

 export HISTTIMEFORMAT="%d/%m/%y %H:%M " 
0
source share

All Articles