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
相关推荐
Han.miracle12 分钟前
JavaEE-- 网络编程 http请求报头
运维·服务器·网络·网络协议·计算机网络·http
鹿鸣天涯35 分钟前
使用VMware Workstation 17虚拟机安装红帽企业版系统RHEL10
linux·运维·服务器
SKYDROID云卓小助手36 分钟前
三轴云台之控制协同技术
服务器·网络·图像处理·人工智能·算法
艾莉丝努力练剑1 小时前
【Git:企业级开发模型】Git企业级Git工作流实战:基于Git Flow的分支模型与开发流程
服务器·git·ubuntu·gitee·centos·powershell·企业级开发模型
杰 .1 小时前
Linux yum_and_apt
linux·服务器
南棱笑笑生1 小时前
20251129给荣品RD-RK3588开发板跑Rockchip的原厂Buildroot【linux-6.1】系统时适配AP6275P的蓝牙BLE
linux·运维·服务器·rockchip
Brown.alexis2 小时前
docker安装redis7
运维·docker·容器
c***21292 小时前
ubuntu 安装 Redis
linux·redis·ubuntu
u***32432 小时前
Mysql官网下载Windows、Linux各个版本
linux·数据库·mysql