Linux之history历史指令查看

Linux之history历史指令查看

history命令用来查看曾经输出过的命令。
命令格式

txt 复制代码
history [选项]

选项

txt 复制代码
n  显示最近条记录
-c 清除历史记录,但是此项清除只是清除当前shell,从新连接还是有历史记录

显示命令时间设置

txt 复制代码
命令history显示时间戳。此命令只是临时的,系统重启就失效
export HISTTIMEFORMAT='%F %T '
export HISTTIMEFORMAT="%F %T "
export HISTTIMEFORMAT="[%Y-%m-%d %H:%M:%S] "
如果需要永久使用,需要在系统环境变量文件(/etc/profile)的末尾追加上
export HISTTIMEFORMAT="%F %T "

例子

txt 复制代码
[root@localhost opt]# history
    1  ls
    2  cd /
    3  ls
    4  ls -l
    ......
[root@localhost opt]# export HISTTIMEFORMAT='%F %T '
[root@localhost opt]# history
    1  2024-06-12 21:18:38 ls
    2  2024-06-12 21:18:38 cd /
    3  2024-06-12 21:18:38 ls
    4  2024-06-12 21:18:38 ls -l
[root@localhost ~]# history -c
[root@localhost ~]# history
    1  history
[root@localhost ~]# history 5
  991  history -10
  992  history 10
  993  history +10
  994  history 10
  995  history 5
相关推荐
云资源服务商2 小时前
解锁阿里云日志服务SLS:云时代的日志管理利器
服务器·阿里云·云计算
绝不偷吃2 小时前
ELK日志分析系统
运维·elk·jenkins
朱包林3 小时前
day45-nginx复杂跳转与https
linux·运维·服务器·网络·云计算
孙克旭_3 小时前
day045-nginx跳转功能补充与https
linux·运维·nginx·https
孞㐑¥4 小时前
Linux之Socket 编程 UDP
linux·服务器·c++·经验分享·笔记·网络协议·udp
Hacker_Oldv5 小时前
软件测试(功能、工具、接口、性能、自动化、测开)详解
运维·自动化
Java樱木5 小时前
使用字节Trae + MCP,UI 到网页自动化。
运维·自动化
柳鲲鹏5 小时前
WINDOWS最快布署WEB服务器:apache2
服务器·前端·windows
无敌暴龙兽z8 小时前
离线环境安装elk及设置密码认证
运维·elk
M4K08 小时前
Linux百度网盘优化三板斧
linux