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

简介: centos6 中history命令显示操作命令的时间和用户身份      [root@bdkyr ~]# 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.
centos6 中history命令显示操作命令的时间和用户身份
    
[root@bdkyr ~]# 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
[root@bdkyr ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@bdkyr ~]#

而centos7中,history命令中不显示操作命令的时间和用户身份
    
[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]#

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

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

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

    
[root@bdkyr 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
[root@bdkyr 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
目录
相关文章
|
3月前
|
Linux
linux centos history 查看命令历史 显示时间戳
linux centos history 查看命令历史 显示时间戳
191 1
|
1月前
|
安全 Linux 网络安全
CentOS常用的命令及其注释
CentOS常用的命令及其注释
|
1月前
|
Web App开发 缓存 Ubuntu
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
122 11
|
3月前
|
Linux C语言 C++
Linux 下centos 查看 -std这个编译时命令 是否支持 C17
Linux 下centos 查看 -std这个编译时命令 是否支持 C17
96 2
|
4月前
|
运维 监控 Linux
【热门话题】CentOS 常见命令指南
此文档是CentOS常用命令指南,涵盖文件操作、系统管理、网络配置、软件安装更新等方面。包括切换目录(`cd`)、查看目录(`ls`)、创建/删除目录(`mkdir`, `rmdir`, `rm`)、文件查看编辑(`cat`, `less`, `vi/vim`)、系统信息(`uname -a`, `hostname`, `top`)、用户权限管理(`useradd`, `passwd`, `sudo`, `chmod`, `chown`)、软件包管理(`yum`或`dnf`)、网络状态(`ip addr`, `ping`)、进程管理(`ps`, `kill`, `nohup`, `jobs`
118 1
|
4月前
|
Web App开发 缓存 运维
CentOS命令大全:从入门到精通
CentOS命令大全:从入门到精通
198 1
|
4月前
|
网络安全
CentOS-7常用命令收集
CentOS-7常用命令收集
42 0
|
4月前
|
XML 安全 Linux
【Linux】深入探究CentOS防火墙(Firewalld):基础概念、常用命令及实例操作
【Linux】深入探究CentOS防火墙(Firewalld):基础概念、常用命令及实例操作
|
4月前
|
Linux
Centos 常见的命令
Centos 常见的命令
34 0
|
4月前
|
监控 网络协议 Linux
centos常见的命令
【5月更文挑战第8天】了解和掌握基本的CentOS命令对于服务器管理至关重要。本文介绍了19个常用命令,包括`ls`、`cd`、`mkdir`、`rm`、`grep`、`find`、`sudo`、`vi/vim`、`cp/mv`、`du/df`、`history`、`top/htop`、`ps`、`netstat/ss`、`yum/dnf`、`ssh`、`iptables`、`journalctl`、`crontab`和`systemctl`。每个命令都提到了常见问题、使用技巧和避免错误的方法,帮助用户更好地管理和维护CentOS系统。
74 0