CENTOS6 The history command displays the time and user identity of the action command
[Email protected] ~]# history 294 2017-01-06 16:46:48 root Clear 295 2017-01-06 16:46:50 Root ll 296 2017-01-06 1 6:46:52 root cat hostname.sh 297 2017-01-06 16:46:56 root cat nginxlog_cut.sh 298 2017-01-06 16:47:29 Root Clear 299 2017-01-06 16:47:34 Root history[[email protected] ~]# cat/etc/redhat-release CentOS release 6.6 (Final) [[Email PR Otected] ~]#
In Centos7, the time and user identity of the action command is not displayed in the history command
[Email protected] data]# cat/etc/redhat-release CentOS Linux release 7.2.1511 (Core) [[email protected] data]# history- n 10[[email protected] data]# 1268 1269 History 1270 Cat/etc/redhat-release 1271 clear 1272 Cat/etc/re Dhat-release 1273 History 1274 Clear 1275 Cat/etc/redhat-release 1276 history-n Ten 1277 history 10[[email protect Ed] data]#
To solve this problem, you only need to add the following variables to the/etc/profile:
Export histtimeformat= "%y-%m-%d%h:%m:%s ' WhoAmI '"
and then run the source/etc/profile command, notice the spaces in the quotation marks
[[email protected] data]# history 10 1273 2017-01-05 19:40:18 root history 1274 2017-01-05 19:40:27 root clear 1275 2017-01-05 19:40:29 root cat /etc/ redhat-release 1276 2017-01-05 19:40:35 root history -n 10 1277 2017-01-05 19:40:39 root history 10 1278 2017-01-05 19:41:12 root cat /etc/profile 1279 2017-01-05 19:42:16 root vim /etc/profile 1280 2017-01-05 19:42:26 root source /etc/profile 1281 2017-01-05 19:42:28 root history 1282 2017-01-05 19:42:42 root history 10[[email protected] data]#
At this time the history command output format is perfectly resolved, if you want to clear historical records, you can use History-c, the following:
Usage and parameters of the history command Usage:history [-c] [-D offset] [n] or HISTORY-ANRW [filename] or history-ps arg [arg ...]
Parameters:
N: number, to list the most recent command lists
-C: Eliminate all history content in the current shell
-A: Add the current New History command to Histfiles, and if there is no histfiles, the default write ~/.bash_history
-r: Read Histfiles's contents into the current Shell's history memory
-W: Writes current history memory content to Histfiles
This article from "Flat Light is true" blog, please be sure to keep this source http://ucode.blog.51cto.com/10837891/1889568
Resolving the CentOS 7 history command does not show the time and user identity issues of the operation record