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
相关推荐
Robpubking2 小时前
AWS 中 S3 的 server-side encryption 解释与说明
运维·aws
福旺旺2 小时前
Linux——解压缩各类文件
linux
MasterLi80234 小时前
我的读书清单
android·linux·学习
ha20428941945 小时前
Linux操作系统学习之---初识网络
linux·网络·学习
飞凌嵌入式5 小时前
【玩转多核异构】T153核心板RISC-V核的实时性应用解析
linux·嵌入式硬件·嵌入式·risc-v
陌路205 小时前
Linux 34TCP服务器多进程并发
linux·服务器·网络
玉树临风江流儿5 小时前
Linux驱动开发实战指南-中
linux·驱动开发
爱喝矿泉水的猛男5 小时前
单周期Risc-V指令拆分与datapath绘制
运维·服务器·risc-v
科技块儿5 小时前
【IP】公有&私有IP地址?
服务器·网络协议·tcp/ip
hakukun5 小时前
docker避免每次sudo方法
运维·docker·容器