Linux View history record plus time stamp tips
You must know that you are familiar with bash. Use history to output historical commands that you have entered, such as
[Email protected]_web ~]# History | More
6./test.sh
7 Vim test.sh
8./test.sh
But this shows only the command, and does not show the time to execute the command, because the ~/.bash_history of the Save History command has no time saved.
Add time stamp to history by setting environment variables export histtimeformat= "%F%T ' WhoAmI '"
[Email protected]_web ~]# export histtimeformat= "%F%T ' WhoAmI '"
[Email protected]_web ~]# History | Tail
1014 2011-06-22 19:17:29 root 2011-06-22 19:13:02 root./test.sh
1015 2011-06-22 19:17:29 root 2011-06-22 19:13:02 root vim test.sh
1016 2011-06-22 19:17:29 root 2011-06-22 19:13:02 root./test.sh
1017 2011-06-22 19:17:29 Root 2011-06-22 19:13:02 root vim test.sh
1018 2011-06-22 19:17:29 root 2011-06-22 19:13:02 root./test.sh
1019 2011-06-22 19:17:29 root 2011-06-22 19:13:02 root vim test.sh
1020 2011-06-22 19:17:29 root 2011-06-22 19:13:02 root./test.sh
1021 2011-06-22 19:17:29 root 2011-06-22 19:13:02 root vim test.sh
1022 2011-06-22 19:25:22 root 2011-06-22 19:13:02 root vim test.sh
1023 2011-06-22 19:25:28 Root History | Tail
As you can see, the timestamp of the history command has been added, but the. Bash_history does not add this timestamp. In fact, this time record is stored in the current shell process memory, if you logout and re-login, you will find that the last time you log on the command to execute the timestamp is the same value, that is, when logout time.
However, for bash with screen, this timestamp can still be effective for a long time, after all, as long as your server does not restart, screen will not exit, so these times can be retained for a long time. You can also use echo ' Export histtimeformat= '%F%T ' whoami ' "' >>/etc/profile then source a bit OK
Linux View history record plus time stamp tips