Linux中history输出格式的定制
2015-09-16 14:22
344 查看
Linux运维同学们经常会用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的输出格式。
正文
以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的输出格式。
相关文章推荐
- Linux系统中一些实用的快捷键
- 超实用的Linux/Unix快捷键大汇总
- linux(centos)搭建SVN服务器
- Linux开启ssh服务
- linux系统下怎么安装.deb文件
- linux下echo命令详解
- 使用 Linux 系统调用的内核命令【转】
- Linux查看和结束进程命令详解
- linux命令大全
- Linux安装svn客户端
- Linux的快捷键和主要命令
- Linux写时拷贝技术(copy-on-write)
- Linux(centos)搭建SVN服务器完美方案及遇到的问题--费元星站长
- Linux下部署web项目
- libevent 服务器框架使用
- 让linux系统支持xfs文件系统
- Linux的inode的理解
- Linux重要文件
- Linux 获取本地ip
- 装机必备:精选十款优秀的Linux应用软件