UNPKG

1.98 kBMarkdownView Raw
1history
2===
3
4用于显示历史命令
5
6## 补充说明
7
8**history命令** 用于显示指定数目的指令命令,读取历史命令文件中的目录到历史命令缓冲区和将历史命令缓冲区中的目录写入命令文件。
9
10该命令单独使用时,仅显示历史命令,在命令行中,可以使用符号`!`执行指定序号的历史命令。例如,要执行第2个历史命令,则输入`!2`
11
12历史命令是被保存在内存中的,当退出或者登录shell时,会自动保存或读取。在内存中,历史命令仅能够存储1000条历史命令,该数量是由环境变量`HISTSIZE`进行控制。
13
14### 语法
15
16```shell
17history(选项)(参数)
18```
19
20### 选项
21
22```shell
23-c:清空当前历史命令;
24-a:将历史命令缓冲区中命令写入历史命令文件中;
25-r:将历史命令文件中的命令读入当前历史命令缓冲区;
26-w:将当前历史命令缓冲区命令写入历史命令文件中。
27```
28
29### 参数
30
31n:打印最近的n条历史命令。
32
33### 实例
34
35使用history命令显示最近使用的10条历史命令,输入如下命令:
36
37```shell
38[root@localhost ~]# history 10
39 92 ls
40 93 cd ..
41 94 ls
42 95 exit
43 96 ls -a
44 97 cd .ssh/
45 98 ls
46 99 cat known_hosts
47 100 exit
48 101 history 10
49```
50
51列出最近3条记录
52
53```shell
54[root@localhost ~]# history 3
55 15 2017-08-26 11:44:35 root history 3
56 16 2017-08-26 11:44:37 root history n
57 17 2017-08-26 11:44:40 root history 3
58```
59
60清空历史记录
61
62```shell
63[root@localhost ~]# history -c
64```
65
66更多实例:
67
68```shell
69history -cw
70`~/.bash_history`: 保存历史命令
71`/etc/profile` -> HISSIZE: 历史命令保存数量
72推荐添加 h -> history, hsi -> history|grep 别名
73`!n`: 执行第 n 条历史命令
74`!xxx`: 执行最后一条 xxx 开头的命令
75```
76
77<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->