Linux View history record plus time stamp tips

Source: Internet
Author: User
Tags add time

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.