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
相关推荐
Bony-31 分钟前
Go语言完全学习指南 - 从基础到精通------语言基础篇
服务器·开发语言·golang
阿巴~阿巴~1 小时前
线程安全单例模式与懒汉线程池的实现与优化
linux·服务器·单例模式·线程池·饿汉模式·懒汉模式·静态方法
大隐隐于野1 小时前
tcp 丢包分析
linux·服务器·网络
梦昼初DawnDream1 小时前
linux安全基线
linux·运维·安全
Broken Arrows1 小时前
在Linux系统中,top命令的显示参数详解
linux·运维·服务器
APIshop2 小时前
PHP:一种强大的服务器端脚本语言
服务器·php
qq_401700413 小时前
I.MX6U 启动方式详解
linux
code-vibe4 小时前
物理机 kali 改造笔记 (一)
linux·运维·服务器
小坏讲微服务4 小时前
五分钟使用 Docker-compose搭建 Redis 8.0 中间件
运维·redis·docker·中间件·容器·kubernetes·k8s
老黄编程4 小时前
03-gpg(证书管理 )详细范例
linux·运维·ubuntu·数字证书