Linux 历史命令巧用
轉載出處:http://hi.baidu.com/nicker2010/item/2062bf09dd20ae3ba2332aef
我們知道bash提供了命令歷史記錄的功能,我們可以使用history命令查詢歷史命令。history命令的用法如下:
history [n] ? ? ? ?<--n為數字,表示列出最近的n條命令,不帶參數的history表示列出目前內存內所有的history命令
history -c ? ? ? ?<--將目前shell中所有的history命令刪除
history -d offset
history -arw [filename] ? ? ? ?<--a表示將目前新增加的命令寫入到histfiles中,默認寫到~、。bash_history文件中;r表示將histfiles中的命令讀入目前shell的history記憶中;-w表示將目前shell的history記憶中的內容寫入到histfiles中。
history -p arg [arg ...]
history -s arg [arg ...]
具體可以參加man history,在查找一下(輸入/history,按n鍵向下查找)。
[root@mail ~]# history 1080 hostname81 cat /etc/hosts82 ifconfig eth083 cat /etc/sysconfig/network84 cat /etc/selinux/config85 vi /etc/selinux/config86 service iptables stop87 service iptables status88 yum install bind bind-chroot caching-nameserver -y89 history 10
系統注銷時候,會將最近的HISTSIZE條記錄到文件中。默認的HISTSIZE為1000.
[root@mail ~]# echo $HISTSIZE 1000
其他的關于history的命令有:
!number ? ? ? ?<--執行第number條命令
!command ? ? ? ?<--由最近的命令向前搜索開頭為command的那個命令
!! ? ? ? ?<--執行上一條命令
[root@mail ~]# history 1082 ifconfig eth083 cat /etc/sysconfig/network84 cat /etc/selinux/config85 vi /etc/selinux/config86 service iptables stop87 service iptables status88 yum install bind bind-chroot caching-nameserver -y89 history 1090 echo $HISTSIZE91 history 10 [root@mail ~]# !87 service iptables status iptables: Firewall is not running. [root@mail ~]# !ech echo $HISTSIZE 1000 [root@mail ~]# !! echo $HISTSIZE 1000 [root@mail ~]# !87 service iptables status iptables: Firewall is not running. [root@mail ~]# !! service iptables status iptables: Firewall is not running.
通常我們可以利用上下鍵來查看前一個/后一個命令。
轉載于:https://blog.51cto.com/hooper/1256228
總結
以上是生活随笔為你收集整理的Linux 历史命令巧用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 将STM32的标准库编译成lib
- 下一篇: 进入bios怎么设置u盘为第一启动项 如