#Bash 的 history 命令
history [OPTION]
功能
显示或操作历史记录列表。
将参数列表
$@向前移动N个参数,即清除前N个参数。
类型
Bash 内置命令。
参数
OPTION选项:-c- 清除历史记录列表-d OFFSET- 删除位置OFFSET处的历史记录条目;OFFSET为负值时表示从后向前计数-a FILE- 将本次会话的历史记录行添加到FILE文件中-n FILE- 读取FILE文件中所有尚未读取的历史记录行,并将它们追加到历史记录列表中-r FILE- 读取FILE文件并将内容追加到历史记录列表中-w FILE- 将当前历史记录写入FILE文件-p ARG...- 对每个ARG执行历史扩展,并显示结果,而不将其存储在历史列表中-s ARG...- 将ARG作为单个条目追加到历史记录列表中
#示例
$ echo 1
1
$ echo 2
2
$ echo 3
3
$ history # 查看历史
...
2104 echo 1
2105 echo 2
2106 echo 3
2107 history
$ history -d 2105 # 删除 2105 号记录
$ history # 查看历史
...
2104 echo 1
2106 echo 3
2107 history
2108 history -d 2105
2109 history
#相关命令
| 命令 | 说明 |
|---|---|
| fc | 查看、编辑或执行历史命令 |
#推荐阅读
#手册
history: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
Display or manipulate the history list.
Display the history list with line numbers, prefixing each modified
entry with a `*'. An argument of N lists only the last N entries.
Options:
-c clear the history list by deleting all of the entries
-d offset delete the history entry at position OFFSET. Negative
offsets count back from the end of the history list
-a append history lines from this session to the history file
-n read all history lines not already read from the history file
and append them to the history list
-r read the history file and append the contents to the history
list
-w write the current history to the history file
-p perform history expansion on each ARG and display the result
without storing it in the history list
-s append the ARGs to the history list as a single entry
If FILENAME is given, it is used as the history file. Otherwise,
if HISTFILE has a value, that is used, else ~/.bash_history.
If the HISTTIMEFORMAT variable is set and not null, its value is used
as a format string for strftime(3) to print the time stamp associated
with each displayed history entry. No time stamps are printed otherwise.
Exit Status:
Returns success unless an invalid option is given or an error occurs.