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
相关推荐
rayyy940 分钟前
Linux 下标准的 libX.so 软链接生成
linux
实心儿儿1 小时前
Linux —— 基础IO - 文件描述符
linux·运维·服务器
clear sky .1 小时前
[linux]视频实时推流项目
linux·服务器·音视频
RisunJan1 小时前
Linux命令-nisdomainname(显示或设置系统的 NIS(Network Information Service)域名)
linux·运维·服务器
Wy_编程1 小时前
nginx测试
服务器·nginx
小此方2 小时前
Re:Linux系统篇(四)指令篇 · 三:两套打包压缩重要指令方法+剩余指令收尾
linux·运维·服务器
冷风阿健2 小时前
Linux 源码安装 Vim 9.2.0272 完整步骤(修复 CVE-2026-34714)
linux·运维·vim
w_t_y_y2 小时前
Claude Code(二)rules
linux·运维·ubuntu
白菜欣2 小时前
Linux —《从零上手Vim:核心用法全解析》
linux·编辑器·vim
小宏运维有点菜2 小时前
服务器 BMC 管理 IP
服务器·tcp/ip·centos