解决CentOS 7 history命令不显示操作记录的时间和用户身份问题

centos6 中history命令显示操作命令的时间和用户身份

[[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 16: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 protected] ~]#

而centos7中,history命令中不显示操作命令的时间和用户身份

[[email protected] data]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
[[email protected] data]# history -n 10
[[email protected] 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
[[email protected] data]#

解决该问题只需要在/etc/profile中添加如下变量即可:

export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S  `whoami` "

然后运行source /etc/profile命令即可,注意引号中的空格

[[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]#

至此history命令输出结果格式完美解决,如果要清除历史记录,可以运用history -c,具体history用法如下:

history命令的用法及参数usage: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]

参数:

n :数字,要列出最近的若干命令列表

-c :将目前的 shell 中的所有 history 内容全部消除

-a :将目前新增的 history 指令新增入 histfiles 中,若没有加 histfiles ,则预设写入 ~/.bash_history

-r :将 histfiles 的内容读到目前这个 shell 的 history 记忆中

-w :将目前的 history 记忆内容写入 histfiles

时间: 2024-08-12 03:13:12

解决CentOS 7 history命令不显示操作记录的时间和用户身份问题的相关文章

history命令不显示时间

有时候系统的history命令不显示时间,但是我们想查看命令执行的时间是什么时候怎么办,下面的命令可以解决: export HISTTIMEFORMAT="%F %T" 不过这种是临时解决办法,如果想永久生效就把这段添加到/etc/profile里边,然后执行source /etc/profile使之生效

CentOS 6下gcc升级的操作记录(由默认的4.4.7升级到6.4.0版本)

机房一台centos6.9机器部署了jenkins发布系统,开发人员在用node编译js,发现依赖的gcc版本低了,故需要将gcc升级到高版本(至少5.0版本以上),这里选择升级到6.4.0版本,下面是升级的操作记录: 1)查看系统版本 [[email protected] ~]# cat /etc/redhat-release CentOS release 6.9 (Final) 2)查看默认的gcc版本 [[email protected] ~]# gcc --version gcc (GC

centos下升级git版本的操作记录

在使用git pull.git push.git clone的时候,或者在使用jenkins发版的时候,可能会报类似如下的错误: error: The requested URL returned error: 401 Unauthorized while accessing https://git.oschina.net/zemo/demo.git/info/refs fatal: HTTP request failed 这个一般是由于服务器本身自带的git版本过低造成的: [[email p

解决centos chrome浏览器页面中文显示为方框

centos安装完成后在chrome中所有中文都显示为方框,解决办法:执行如下三条命令 yum groupinstall "X Window System" -y yum -y groupinstall chinese-support yum -y groupinstall Fonts 原文地址:https://www.cnblogs.com/shengs/p/11329078.html

杂了个谈(三)——解决CentOS下yum命令报404错误的问题

最近在CentOS 6.6 x64操作系统下使用yum时会报如图-1所示的404错误: 图-1 yum命令报错信息 由于错误类型是404,首先想到的是是不是外网上不去了,结果能ping通,试了一下其他虚拟机,yum并没有出现同样的问题,而出错的虚拟机上也并没有印象对yum的配置等做过修改.无奈之下在网上搜了一下,发现下面这种方法可以解决问题: [[email protected] ~]# yum clean all [[email protected] ~]# rpm --rebuilddb [

解决CentOS下man 命令,没有帮助信息

Cannot open the message catalog "man" for locale "zh_CN.UTF-8" (NLSPATH="/usr/share/locale/%l/LC_MESSAGES/%N") No manual entry for abc 两种方法都试了才解决办法: 1. yum install man-pages 3. cp /usr/share/locale/en/LC_MESSAGES/man /usr/sha

Centos下安装破解Jira7的操作记录

Jira是一个集项目计划.任务分配.需求管理.错误跟踪于一体的工具,可以作为一个bug管理系统,可以将在测试过程中所发现的bug录入.分配给开发人员.前面介绍了Confluence在Centos下的安装破解记录,下面说下Jira7的安装破解的方法(jira和之前的confluence在同一台服务器上部署): 一.安装jdk8环境(已在confluence部署中安装)二.创建jira数据库及jira用户 [[email protected] ~]# mysql -p123456 Welcome t

centos用lastb命令看失败登录记录

lastb |less lastb |tail lastb |head 可以写个脚本,失败多少次后,就扔到/etc/hosts.deny里面去 如: lastb |awk '{print $3}' |sort |uniq -c |sort -rn |awk '{print $2}' |head -25 |while read L;do echo "sshd:$L" >> /etc/hosts.deny;done 不生效可能是因为ldd /usr/sbin/sshd后没找到l

linux下history命令显示历史指令记录的使用方法

linux下history命令显示历史指令记录的使用方法 History命令主要用于显示历史指令记录内容, 下达历史纪录中的指令 .1>History命令语法: [[email protected]]# history [n][[email protected]]# history [-c][[email protected]]# history [-raw] histfiles参数:n   :数字,要列出最近的 n 笔命令列表-c  :将目前的shell中的所有 history 内容全部消除-