0
点赞
收藏
分享

微信扫一扫

Linux战地日记——历史命令


历史命令

历史命令存放在.~/.bash_history中,他在用户主目录下。

通过输入$ history可查询当前历史命令

[bestcoder@localhost test1]$ history
1 history
2 history -a
3 history
4 pwd
5 date
6 cat test1
7 cd test1
8 history


通过-c选项可删除历史文件中的所有清单

[bestcoder@localhost ~]$ history
1 history



执行历史命令

命令替换的方式之一,以“!”开头。

格式

 !!   重复上一条命令

!n   重复第n条命令

!-n  重新执行倒数第n条命令

!ca 重新执行以ca开头的命令

!?string?  重新执行最新的包含字符串string的历史命令

!#   到目前所输入的整个命令行

[bestcoder@localhost test1]$ !2
history -a
[bestcoder@localhost test1]$ !4
pwd
/home/bestcoder/test1
[bestcoder@localhost test1]$ !date
date
2015年 09月 09日 星期三 22:28:13 PDT



可通过$ HISTFILE="/home/test/.myhistory"指定存放历史命令的文件。

可通过$ HISTSIZE=600指定bash保存的历史命令。


举报

相关推荐

0 条评论