10、history 可以查看命令历史记录,每一条命令前面都会有一个序列号标示。
10.1.1 命令语法: history [选项]
10.1.2 选项参数
history命令选项参数含义
选项 选项含义
-c 清除命令历史记录
-w 让bash将历史命令立即从内存写到.bash_history文件
-a 将目前新增的history历史命令写入.bash_history文件
n 显示最近n个命令历史记录,n代表数字
-r 读取历史文件的内容,并把它们作为当前历史
10.1.2 调用历史命令
例1,列出目前内存内的所有 history 历史记录
[root@localhost~]#history # 前面省略 1017 man bash 1018 ll 1019 history 1020 history
列出的信息当中,共分两栏,第一栏为该命令在这个 shell 当中的代码, 另一个则是命令本身的内容!至于会显示多少条命令记录,则与 HISTSIZE 有关!
例2,列出目前最近的 3 条数据
[root@localhost~]#history 3 1019 history 1020 history 1021 history 3
例3,立刻将目前的数据写入 histfile 当中
[root@localhost~]#history -w # 在默认的情况下,会将历史纪录写入 ~/.bash_history 当中! [root@localhost~]#echo $HISTSIZE 1000