The function of the history command is to display and number the used commands. The following commands are the different operations of the history:
History n shows the most recently used n commands.
History-c clears the history of the current shell.
history-d 801 Delete the command with number 801.
History-a append the latest command to the history file.
History-n shows a history that has not yet been read from the history file.
History-r the record in the history file as the history of the current shell.
History-w writes the current record to the history file, overwriting the original content.
The system default History command is difficult to meet our needs, we can modify the/etc/profile file to the hostory command
To modify the display effect:
(1) Show the time of the command execution
Add at the end of the/etc/profile file: Export histtimeformat= "%F%T ' WhoAmI ':" (note: Here WhoAmI both sides of the symbol is not a single quotation mark, but the TAB key above the symbol of the key, that is ~ the symbol below.) )
(2) Displays the source IP of the user executing the command
First get login source ip:user_ip= ' who-u am I 2>/dev/
null | awk ' {print &nf} ' | Sed-e ' s/[()]//g "
If ["&user_ip" = ""]
Then
User_ip= ' hostname '
Then export Histtimeformat, user_ip as a parameter to write Histtimeformat,
Export histtimeformat= "%F%T &user_ip: ' WhoAmI ':"
Combining the above tips, we can get the following script:
user_ip= ' who-u am I 2>/dev/null | awk ' {print &nf} ' |sed-e ' s/[()]//g '
If ["&user_ip" = ""]
Then
User_ip= ' hostname '
Fi
if [!-d/opt/history]
Then
Mkdir/opt/history
chmod 777/opt/history
Fi
if [!-d/opt/history/&{logname}]
Then
Mkdir/opt/history/&{logname}
chmod 300/opt/history/&{logname}
Fi
Export histsize=4096
Export histtimeformat= "[%y-%m-%d%h:%m:%s]"
Export histfile= "/opt/history/${logname}.history"
chmod 600/opt/history/*history* 2>/dev/null
Append the above code to the end of the/etc/profile file and log in again, and you will find that the display format of the history and the storage file are changed.
Learn Linux commands every day--history