history查询历史命令

简介:

history 命令用于查询已执行的历史命令。

常用参数:

n :数字,表示列出最近n行命令

-c :将目前的shell中的所有的history内容删除

-a:将目前新增的history命令新增入histfile中,若没有加hisfiles,则默认写入~/.bash_history

-r:将histfiles的内容读到目前这个shell 的history记忆中。

-w:将目前的history记忆内容写入histfiles中。

 

 

查看所有history记忆中的命令:

1
2
3
4
5
6
7
8
[root@abcdefghijklmnopqrstuvwxyzabcdefghijkl123456789012~] # history
1   df -h
2 reboot
ssh  esggy-qa-n013
4 yum  install  nfs-utils
5 yum  install  parted
6 yum  install  nfs-utils

 

查看history的最后6条命令:

1
2
3
4
5
6
7
[root@abcdefghijklmnopqrstuvwxyzabcdefghijkl123456789012~] # history  6
395  su  - trafodion
396 hive
397  history
398  history  n
399  history  3
400  history   6

 

将目前的已执行的命令添加到histfile中,默认为~/.bash_history并查看文件内容:

1
2
3
4
5
6
7
8
9
10
11
12
[root@abcdefghijklmnopqrstuvwxyzabcdefghijkl123456789012~] # history -w
[root@abcdefghijklmnopqrstuvwxyzabcdefghijkl123456789012~] # cat ~/.bash_history | tail -n 10
clear
hive
su  - trafodion
hive
history
history  n
history  3
history  6
echo  $HISTORY
history  -w

将新增的history命令加到histfile中,并查看文件内容:

1
2
3
4
5
6
7
8
9
10
11
12
[root@abcdefghijklmnopqrstuvwxyzabcdefghijkl123456789012~] # history -a
[root@abcdefghijklmnopqrstuvwxyzabcdefghijkl123456789012~] # cat ~/.bash_history | tail -n 10
history  n
history  3
history  6
echo  $HISTORY
history  -w
echo  $HISTORY
cat  ~/.bash_history
cat  ~/.bash_history |  tail  10
cat  ~/.bash_history |  tail  -n 10
history  -a

 

查看HISTSIZE /.bashhistoryHISTSIZE决定):

1
2
[root@abcdefghijklmnopqrstuvwxyzabcdefghijkl123456789012~] # echo $HISTSIZE
1000

 

使用!执行命令:

! 命令行号 (执行history中指定行号的命令)

! 字符串 (执行最近以指定字符串开头的命令)

!! (执行上一条命令) 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@abcdefghijklmnopqrstuvwxyzabcdefghijkl123456789012~] # history 5
406  cat  ~/.bash_history |  tail  -n 10
407  history  -a
408  cat  ~/.bash_history |  tail  -n 10
409   echo  $HISTSIZE
410  history  5
[root@abcdefghijklmnopqrstuvwxyzabcdefghijkl123456789012~] # !410
history  5
406  cat  ~/.bash_history |  tail  -n 10
407  history  -a
408  cat  ~/.bash_history |  tail  -n 10
409  echo  $HISTSIZE
410  history  5
[root@abcdefghijklmnopqrstuvwxyzabcdefghijkl123456789012~] # !!
history  5
406  cat  ~/.bash_history |  tail  -n 10
407  history  -a
408  cat  ~/.bash_history |  tail  -n 10
409  echo  $HISTSIZE
410  history  5
[root@abcdefghijklmnopqrstuvwxyzabcdefghijkl123456789012~] # !ec
echo  $HISTSIZE
1000



本文转自 天黑顺路 51CTO博客,原文链接:http://blog.51cto.com/mjal01/1963004,如需转载请自行联系原作者
目录
打赏
0
0
0
0
265
分享
相关文章
8-2|如何查看history带日期
8-2|如何查看history带日期
使用history.pushState管理浏览历史
使用history.pushState管理浏览历史
Confluence 6.15 修改历史(Change-History)宏
修改历史(Change-History)宏显示了页面一个的更新历史:版本号,作者,日期和备注。这些内容将会在同一栏中进行显示。 屏幕截图:Confluence 中的修改历史(Change-History)宏 为了向页面中插入修改历史宏:  从编辑工具栏中,选择 插入(Insert)   > 其他宏(Other Macros)找到并且选择需要的宏。
843 0
[20180322]查看统计信息的保存历史.txt
[20180322]查看统计信息的保存历史.txt --//链接:http://www.itpub.net/thread-2100595-1-1.html --//提到sysaux表空间暴涨.
786 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等