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
相关推荐
BeyondESH2 分钟前
Linux线程同步—竞态条件和互斥锁(C语言)
linux·服务器·c++
wn5313 分钟前
【Go - 类型断言】
服务器·开发语言·后端·golang
hanniuniu134 分钟前
详细解读,F5服务器负载均衡的技术优势
运维·服务器·负载均衡
鱼饼6号18 分钟前
Prometheus 上手指南
linux·运维·centos·prometheus
Asher Gu23 分钟前
Linux系统编程入门 | 模拟实现 ls -l 命令
linux
PatrickYao042237 分钟前
记一次安装discuz时遇到的错误
服务器
c无序40 分钟前
【Linux进程控制】进程程序替换
linux
小宋10212 小时前
玩转RabbitMQ声明队列交换机、消息转换器
服务器·分布式·rabbitmq
m0_609000422 小时前
向日葵好用吗?4款稳定的远程控制软件推荐。
运维·服务器·网络·人工智能·远程工作
小安运维日记3 小时前
Linux云计算 |【第四阶段】NOSQL-DAY1
linux·运维·redis·sql·云计算·nosql