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
相关推荐
a***5926几秒前
用nginx正向代理https网站
运维·nginx·https
S***26756 分钟前
linux上redis升级
linux·运维·redis
赖small强23 分钟前
【Linux 网络基础】Linux 平台 DHCP 运作原理与握手过程详解
linux·网络·dhcp
ifanatic42 分钟前
[每周一更]-(第161期):分析服务器中内存即将爆满过程
运维·服务器
热爱学习的小怪兽1 小时前
docker的一些常用指令
运维·docker·容器
s***4532 小时前
Linux 下安装 Golang环境
linux·运维·golang
JobDocLS2 小时前
Ubuntu22.04的安装方法
运维
丸子哥哥3 小时前
同一个域名,如何添加多个网站?
服务器·前端·nginx·微服务
豆豆的java之旅3 小时前
深入浅出Activity工作流:从理论到实践,让业务流转自动化
java·运维·自动化·activity·工作流
J***51683 小时前
Linux安装Redis以及Redis三种启动方式
linux·redis·bootstrap