history实时写入带时间戳命令
来源:互联网 发布:多米音乐java 编辑:程序博客网 时间:2024/06/04 18:03
在bash中,所执行的命令可以用history显示出来,但是bash的机制是:先将命令写入baffer,退出shell时才会写入.bash_history文件中,所以最后.bash_history文件中的命令无法分辨出来时间,解决这个问题可以采用时间戳的方法。
bash中提供了时间戳的参数HISTTIMEFORMAT
有了这个参数,可以让执行的命令用history显示时,前面加上时间戳。举例如下:
1011 root 192.168.1.119 2011-03-12 14:49:43 cd /
1012 root 192.168.1.119 2011-03-12 14:49:45 ls
1013 root 192.168.1.119 2011-03-12 14:49:53 vi /etc/profile
1014 root 192.168.1.119 2011-03-12 14:49:59 vi /etc/hosts
1015 root 192.168.1.119 2011-03-12 14:50:12 vi /etc/resolv.conf
1016 root 192.168.1.119 2011-03-12 14:50:15 history
1017 root 192.168.1.119 2011-03-12 14:51:23 cat /etc/profile
1018 root 192.168.1.119 2011-03-12 14:51:30 cat /etc/hosts
1019 root 192.168.1.119 2011-03-12 14:51:35 cat /etc/hosts.allow
1020 root 192.168.1.119 2011-03-12 14:51:39 cat /etc/hosts.deny
1021 root 192.168.1.119 2011-03-12 14:51:48 cat /etc/resolv.conf
1022 root 192.168.1.119 2011-03-12 14:51:51 history
另外就是需要让bash实时写入历史命令。在 /etc/profile 里添加下面的参数:
bash中提供了时间戳的参数HISTTIMEFORMAT
HISTTIMEFORMAT
If this variable is set and not null, its value is used as a format string for strftime(3) to print the time stamp associated with each history entry displayed by the history builtin. If this variable is set, time stamps are written to the history file so they may be pre-served across shell sessions.
有了这个参数,可以让执行的命令用history显示时,前面加上时间戳。举例如下:
1011 root 192.168.1.119 2011-03-12 14:49:43 cd /
1012 root 192.168.1.119 2011-03-12 14:49:45 ls
1013 root 192.168.1.119 2011-03-12 14:49:53 vi /etc/profile
1014 root 192.168.1.119 2011-03-12 14:49:59 vi /etc/hosts
1015 root 192.168.1.119 2011-03-12 14:50:12 vi /etc/resolv.conf
1016 root 192.168.1.119 2011-03-12 14:50:15 history
1017 root 192.168.1.119 2011-03-12 14:51:23 cat /etc/profile
1018 root 192.168.1.119 2011-03-12 14:51:30 cat /etc/hosts
1019 root 192.168.1.119 2011-03-12 14:51:35 cat /etc/hosts.allow
1020 root 192.168.1.119 2011-03-12 14:51:39 cat /etc/hosts.deny
1021 root 192.168.1.119 2011-03-12 14:51:48 cat /etc/resolv.conf
1022 root 192.168.1.119 2011-03-12 14:51:51 history
另外就是需要让bash实时写入历史命令。在 /etc/profile 里添加下面的参数:
#用以实时写入history
export PROMPT_COMMAND="history -a"
#history带登录用户名、客户端IP、时间戳
export HISTTIMEFORMAT="$LOGNAME `echo $SSH_CLIENT | awk {'print $1'}` %F %T "
- history实时写入带时间戳命令
- history命令添加时间---测试磁盘写入速度
- history命令中添加时间
- history 命令显示时间记录
- Linux history命令加入时间
- history命令显示操作时间
- history命令查看操作时间
- liunx多终端history命令实时同步
- 使用HISTTIMEFORMAT 显示history命令的时间戳
- 如何给history命令记录加上时间戳
- history 显示时间戳
- linux给history命令添加时间
- [Linux]history 显示命令执行的时间
- history命令添加时间和使用技巧
- 让自己的history命令显示时间
- 为history加时间戳
- Linux history显示时间戳
- 设置linux系统history相关变量,命令时间、保存history条数,多session共享history
- Linux环境下text model与X model的切换
- Com编程学习资料
- Android build 只能用 sun-java5-jdk
- 算法人生
- ASP.NET验证码
- history实时写入带时间戳命令
- 修改帐号登录密码
- Bootloader V110929.02
- memcache connect queue
- 46个Flex和actionscript3开源项目
- Linux 备份MySQL 并压缩
- SICP练习题 1.3~1.6
- 拟声词译法
- SourceInsight设置