天天看點

linux history

linux指令總結—history指令

(1)指令功能

history指令用于顯示指定數目的指令指令,讀取曆史指令檔案中的目錄到曆史指令緩沖區和将曆史指令緩沖區中的目錄寫入曆史指令檔案。

說明:bash啟動的時候會讀取~/.bash_history檔案并載入到記憶體中,這個變量就用于設定.bash_history檔案,bash退出時也會把記憶體中的曆史回寫到.bash_history檔案,即history中顯示的指令隻儲存在目前曆史指令緩沖區中,隻有退出登陸後系統才會把緩沖區的内容寫入到曆史指令檔案中,當然也可以使用下面的指令參數實作。

(2)指令文法

history(選項) (參數)

(3)選項說明

-c:清空目前曆史指令;

-d <行号>:清除指定行号的曆史輸入指令;

-a:将曆史指令緩沖區中的指令寫入曆史指令檔案中;

-r:将曆史指令檔案中的指令讀入目前曆史指令緩沖區;

-w:将目前曆史指令緩沖區指令寫入曆史指令檔案中。

(4)參數說明

n:列印最近的n條曆史指令。

(5)執行個體

執行個體1:顯示曆史指令—history 數字

1

2

3

4

5

6

7

8

9

10

11

<code>[root@moban ~]#history </code><code>10</code>

<code>  </code><code>991</code> <code>alias</code>

<code>  </code><code>992</code> <code>alias -p</code>

<code>  </code><code>993</code> <code>man cd</code>

<code>  </code><code>994</code> <code>unalias network</code>

<code>  </code><code>995</code> <code>type network</code>

<code>  </code><code>996</code> <code>alias network=</code><code>'cat /etc/sysconfig/network-scripts/ifcfg-eth0'</code>

<code>  </code><code>997</code> <code>unalias network</code>

<code>  </code><code>998</code> <code>type network</code>

<code>  </code><code>999</code> <code>man history</code>

<code> </code><code>1000</code> <code>history </code><code>10</code>

       執行個體2:清除指定行号曆史輸入指令—history -d 行号

<code>[root@moban ~]#history -d </code><code>1000</code>

<code>[root@moban ~]#history </code><code>5</code>

<code> </code><code>1000</code> <code>history -d </code><code>1000</code>

<code> </code><code>1001</code> <code>history </code><code>5</code>

可以看到執行個體1中的曆史輸入指令“1000  history 10”已被清除。

執行個體3:執行指定行号的曆史輸入指令--! 行号

<code> </code><code>1002</code> <code>pwd</code>

<code> </code><code>1003</code> <code>history </code><code>5</code>

<code>[root@moban ~]#!</code><code>1002</code>

<code>pwd</code>

<code>/root</code>

執行個體4:運作上一個輸入指令— !!

<code>[root@moban ~]# pwd</code>

<code>[root@moban ~]# !!</code>

執行個體5:将曆史指令緩沖區中的指令寫入曆史指令檔案中—history -a

12

13

14

15

16

17

18

19

20

21

22

23

<code>[root@moban ~]# tail -</code><code>10</code> <code>.bash_history</code>

<code>cat .bash_history </code>

<code>more .bash_history</code>

<code>history -</code><code>5</code>

<code>history </code><code>5</code>

<code>ls -a</code>

<code>sz .bash_history</code>

<code>init  </code><code>6</code>

<code>[root@moban ~]#history -a</code>

<code>history </code><code>3</code>

<code>history </code><code>10</code>

<code>sy -y .bash_history</code>

<code>sz -y .bash_history</code>

<code>tail -</code><code>10</code><code>.bash_history</code>

<code>history -a</code>

上一篇: linux cp
下一篇: 轉 八步學SVN

繼續閱讀