轉載出處:http://hi.baidu.com/nicker2010/item/2062bf09dd20ae3ba2332aeflinux
咱們知道bash提供了命令歷史記錄的功能,咱們可使用history命令查詢歷史命令。history命令的用法以下:shell
history [n] <--n爲數字,表示列出最近的n條命令,不帶參數的history表示列出目前內存內全部的history命令bash
history -c <--將目前shell中全部的history命令刪除ide
history -d offsetspa
history -arw [filename] <--a表示將目前新增長的命令寫入到histfiles中,默認寫到~、。bash_history文件中;r表示將histfiles中的命令讀入目前shell的history記憶中;-w表示將目前shell的history記憶中的內容寫入到histfiles中。server
history -p arg [arg ...]ip
history -s arg [arg ...]內存
具體能夠參加man history,在查找一下(輸入/history,按n鍵向下查找)。it
[root@mail ~]# history 10 80 hostname 81 cat /etc/hosts 82 ifconfig eth0 83 cat /etc/sysconfig/network 84 cat /etc/selinux/config 85 vi /etc/selinux/config 86 service iptables stop 87 service iptables status 88 yum install bind bind-chroot caching-nameserver -y 89 history 10
系統註銷時候,會將最近的HISTSIZE條記錄到文件中。默認的HISTSIZE爲1000.table
[root@mail ~]# echo $HISTSIZE 1000
其餘的關於history的命令有:
!number <--執行第number條命令
!command <--由最近的命令向前搜索開頭爲command的那個命令
!! <--執行上一條命令
[root@mail ~]# history 10 82 ifconfig eth0 83 cat /etc/sysconfig/network 84 cat /etc/selinux/config 85 vi /etc/selinux/config 86 service iptables stop 87 service iptables status 88 yum install bind bind-chroot caching-nameserver -y 89 history 10 90 echo $HISTSIZE 91 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.
一般咱們能夠利用上下鍵來查看前一個/後一個命令。