The Linux history command displays the user name and operation time

Source: Internet
Author: User

Linux System when you enter and execute commands in the shell (console), the shell automatically logs your commands to the history list, which is typically saved in the. bash_history file in the user directory. By default,historydoes not log the execution time of the command, and if you want to record which user executed some of the commands, we need to modify the/etc/profile file to implement

First, the history shows that the user name and command execution time is relatively simple, as long as the /etc/profile file is appended

Export histtimeformat= "%F%T ' WhoAmI '"


If you want to display the login IP, you need to obtain the source login IP First:

user_ip= ' who-u am I 2>/dev/null| awk ' {print $NF} ' |sed-e ' s/[()]//g "

If ["$USER _ip" = ""]

Then

User_ip= ' hostname '

Fi


then the user_ip Write Histtimeformat can

Export histtimeformat= "%F%T ' whoami ' $USER _ip"


Then Source/etc/profile ( takes effect immediately without having to log back in ) to perform the history | More


2014-12-08 10:05:09 root 192.168.10.136 history

1001 2014-12-08 10:14:24 root 192.168.10.136 cd root

1002 2014-12-08 10:14:27 root 192.168.10.136 ls

1003 2014-12-08 10:14:30 Root 192.168.10.136 cd/opt

Note: When the HISTTIMEFORMAT environment variable is set, the execution time is recorded by the newly executed bash commands , and the time of the command execution is not recorded until the Histtimeformat variable is set.


The Linux history command displays the user name and operation time

Related Article

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.