Solve the problem that the CentOS 7 history command does not display the operation record time and user identity.
The history command in centos6 displays the operating Command time and user identity.
[Root @ bdkyr ~] # History
294 16:46:48 root clear
295 16:46:50 root ll
296 16:46:52 root cat hostname. sh
297 16:46:56 root cat nginxlog_cut.sh
298 16:47:29 root clear
299 16:47:34 root history
[Root @ bdkyr ~] # Cat/etc/redhat-release
CentOS release 6.6 (Final)
[Root @ bdkyr ~] #
In centos 7, The history command does not display the time and user identity of the Operation Command.
[Root @ bdkyr data] # cat/etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[Root @ localhost data] # history-n 10
[Root @ localhost data] # history 10
1268 \
1269 history
1270 cat/etc/redhat-release
1271 clear
1272 cat/etc/redhat-release
1273 history
1274 clear
1275 cat/etc/redhat-release
1276 history-n 10
1277 history 10
[Root @ bdkyr data] #
To solve this problem, you only need to add the following variables to/etc/profile:
Export HISTTIMEFORMAT = "% Y-% m-% d % H: % M: % S 'whoam '"
Run the source/etc/profile command. Pay attention to the spaces in the quotation marks.
[Root @ bdkyr data] # history 10
1273 19:40:18 root history
1274 19:40:27 root clear
1275 19:40:29 root cat/etc/redhat-release
1276 19:40:35 root history-n 10
1277 19:40:39 root history 10
1278 19:41:12 root cat/etc/profile
1279 19:42:16 root vim/etc/profile
1280 19:42:26 root source/etc/profile
1281 19:42:28 root history
1282 19:42:42 root history 10
[Root @ bdkyr data] #
At this point, the output result format of the history command is perfectly solved. To clear historical records, you can use history-c. The specific history usage is as follows:
History command usage and parameter usage: history [-c] [-d offset] [n] or history-anrw [filename] or history-ps arg [arg...]
Parameters:
N: Number. to list the latest commands
-C: removes all history content in the current shell.
-A: adds the newly added history command to histfiles. If histfiles is not added, it is written to ~ by default ~ /. Bash_history
-R: Read the content of histfiles to the history Memory of the current shell.
-W: Write the Current history Memory into histfiles