千家信息网

history命令详解

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,1、manual说明Display or manipulate the history list显示或操作命令历史列表2、概念区分history list是在内存缓存中的,history file就是
千家信息网最后更新 2026年11月02日history命令详解

1、manual说明
Display or manipulate the history list
显示或操作命令历史列表
2、概念区分
history list是在内存缓存中的,history file就是在硬盘中的。history list针对当前会话生效。history file 则针对所有会话都生效。当登录系统系统时,系统就会自动将history list中,当退出系统时,history list中的命令就会自动写入到history file中去。
~/.bash_history 历史列表的默认保存位置
~/.bash_profile 当前用户的环境变量的设置位置
/etc/profile 系统环境变量的默认设置位置
关于HISTORY的变量:
HISTSIZE 命令历史记录的条数
HISTFILE 指定历史文件,默认为~/.bash_history
HISTFILESIZE: 命令历史文件记录历史的条数
HISTTIMEFORMAT: HISTTIMEFORMAT="%F%T" 显示时间
history用法:
history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
Display the history list with line numbers, prefixing each modified entry with a `'. An argument of N lists only the last N entries
显示带有行号的历史记录列表,并在每个修改前加上前缀
带有"
"的条目。N的参数只列出最后的N个元素。
Options:
-c: clear the history list by deleting all of the entries
通过删除所有条目来清除历史记录列表

-d offset: delete the history entry at offset OFFSET
在偏移位置删除历史记录项(就是删除指定数字的历史条目)

-a: append history lines from this session to the history file
将此会话的历史记录行追家到历史记录文件

-n: read all history lines not already read from the history file 。
读取尚未从历史文件中读取的所有历史记录行

-r: read the history file and append the contents to the history list
读取历史文件然后追加到历史记录文件中

-w: write the current history to the history file and append them to the history list
将当前历史写入到历史文件中,同时将他们追加到历史列表中。

-p: perform history expansion on each AGR and dispay the result without storing it in the history list
对每个参数执行历史扩展并显示结果,而不将其存储在历史列表中

-s: append the ARGs to the history list as a single entry
添加所有ARGs作为单独的条目到历史记录条目中。

其他比较常用的用法:
(一):查看历史命令
history #显示所有历史命令'
history 10 #显示最近的10条命令
(二)查看默认历史命令条数:
echo $HISTSIZE
这个环境变量定义在/etc/profile中
(三)命令重新调用
ls !407 #重新调用历史命令中的正数第407个命令
ls !-4 #重新调用历史中的倒数第4条命令
历史命令分两部分存放: .bash_history 和内存中
正常退出时,内存中的历史命令会存储到.bash_history中
(四)执行前面倒数第一个以shut开头的命令
!shut
(五)执行前面一个包含go的命令
!?go
(六)执行刚刚执行过的命令
1、上下键翻
2、!-1
(七)搜索执行过的命令

历史 命令 文件 历史文件 条目 系统 位置 变量 内存 环境 参数 就是 存储 上下 元素 前缀 同时 尚未 常用 开头 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网络科技 上海睿民互联网科技有限公司 云之行互联网科技 北京互联网科技公司 互联网与新科技 杭州互联网科技公司 互联网科技公司名称 科技大学互联网专业好不好 汉立互联网科技有限公司联系电话 南平创想时代互联网科技有限公司 996高科技互联网公司 如何创新互联网科技 工业互联网山东科技大学 国大互联网教育科技有限公司薪资 银行科技岗属于互联网吗 本届互联网大会上的黑科技 南京一网一红互联网科技有限公司 山东大美朱楼互联网科技有限公司 互联网科技机房 瑞安市蟠桃会互联网科技有限公司 博彦科技互联网金融 今日互联网科技 深圳互联网络科技有限公司 深圳国际航运科技和互联网 恒银科技与互联网金融 央行互联网金融科技公司 昭通互联网科技选哪家 迪庆互联网科技招生 福建互联网展示科技馆设计 广州全民伙伴互联网科技有限公司
0