Linux中history输出格式的定制

摘要

运维同学们经常会用history命令来查看命令的历史记录,有时候是为了查找”犯罪证据“,但因为history命令输出默认只有ID和command,查找的同学还想知道命令对应的,有没有办法让也显示出来呢?办法是有的。本文主要讲讲相关的配置。

正文

以root用户登录,在/etc/profile.d/下新建一个文件history_command

vim /etc/profile.c/history_command

export HISTFILE=$HOME/.bash_history

export HISTSIZE=1200

export HISTFILESIZE=1200

export HISTCONTROL=ignoredups

export HISTTIMEFORMAT=”`whoami` %F %T “

shopt -s histappend

typeset -r HISTTIMEFORMAT

source /etc/profile.c/history_command ,使其生效,再敲history命令看看:

#history 5

1008  root 2015-09-11 08:54:20 vim /etc/profile

1009  root 2015-09-11 09:13:17 history | less

1010  root 2015-09-11 09:15:49 vim /etc/profile

1011  root 2015-09-11 09:43:20 cat /etc/profile.d/history_command

1012  root 2015-09-11 09:44:59 history 5

已经有了,/etc/profile和/etc/profile.d/下的文件会在用户interactive login的时候自动执行,所以用户登录机器后每敲一个命令都会被记录到HISTFILE指定的文件中,而且是以追加的方式写入的。

配置中最关键的地方是export HISTTIMEFORMAT=”`whoami` %F %T ” , 这一行指定history的输出格式。

转载自:https://www.linuxidc.com/Linux/2015-09/122949.htm

声明: 除非转自他站(如有侵权,请联系处理)外,本文采用 BY-NC-SA 协议进行授权 | 智乐兔
转载请注明:转自《Linux中history输出格式的定制
本文地址:https://www.zhiletu.com/archives-4612.html
关注公众号:智乐兔

赞赏

wechat pay微信赞赏alipay pay支付宝赞赏

上一篇
下一篇

相关文章

在线留言

你必须 登录后 才能留言!

在线客服
在线客服 X

售前: 点击这里给我发消息
售后: 点击这里给我发消息

智乐兔官微