熱搜:win11繞過硬件限制安裝 一鍵重裝Win10系統(tǒng) 最干凈的u盤啟動(dòng)盤 真正純凈版的win7系統(tǒng)
時(shí)間:2014-12-26 11:28:57 作者:qipeng 來源:系統(tǒng)之家 1. 掃描二維碼隨時(shí)看資訊 2. 請(qǐng)使用手機(jī)瀏覽器訪問: https://m.xitongzhijia.net/xtjc/20141226/33495.html 手機(jī)查看 評(píng)論 反饋
8.使用 HISTCONTROL 從命令歷史中剔除連續(xù)重復(fù)的條目
在下面的例子中,pwd 命令被連續(xù)執(zhí)行了三次。執(zhí)行 history 后你會(huì)看到三條重復(fù)的條目。要剔除這些重復(fù)的條目,你可以將 HISTCONTROL 設(shè)置為 ignoredups:
代碼如下:
# pwd
# pwd
# pwd
# history | tail -4
44 pwd
45 pwd
46 pwd [Note that there are three pwd commands in history, after executing pwd 3 times as shown above]
47 history | tail -4
# export HISTCONTROL=ignoredups
# pwd
# pwd
# pwd
# history | tail -3
56 export HISTCONTROL=ignoredups
57 pwd [Note that there is only one pwd command in the history, even after executing pwd 3 times as shown above]
58 history | tail -4
9.使用 HISTCONTROL 清除整個(gè)命令歷史中的重復(fù)條目
上例中的 ignoredups 只能剔除連續(xù)的重復(fù)條目。要清除整個(gè)命令歷史中的重復(fù)條目,可以將 HISTCONTROL 設(shè)置成 erasedups:
代碼如下:
# export HISTCONTROL=erasedups
# pwd
# service httpd stop
# history | tail -3
38 pwd
39 service httpd stop
40 history | tail -3
# ls -ltr
# service httpd stop
# history | tail -6
35 export HISTCONTROL=erasedups
36 pwd
37 history | tail -3
38 ls -ltr
39 service httpd stop
[Note that the previous service httpd stop after pwd got erased]
40 history | tail -6
10.使用 HISTCONTROL 強(qiáng)制 history 不記住特定的命令
將 HISTCONTROL 設(shè)置為 ignorespace,并在不想被記住的命令前面輸入一個(gè)空格:
代碼如下:
# export HISTCONTROL=ignorespace
# ls -ltr
# pwd
# service httpd stop [Note that there is a space at the beginning of service, to ignore this command from history]
# history | tail -3
67 ls -ltr
68 pwd
69 history | tail -3
11.使用 -c 選項(xiàng)清除所有的命令歷史
如果你想清除所有的命令歷史,可以執(zhí)行:
代碼如下:
# history -c
12.命令替換
在下面的例子里,!。$ 將為當(dāng)前的命令獲得上一條命令的參數(shù):
代碼如下:
# ls anaconda-ks.cfg
anaconda-ks.cfg
# vi 。。$
vi anaconda-ks.cfg
補(bǔ)充:使用 !$ 可以達(dá)到同樣的效果,而且更簡單。
下例中,!^ 從上一條命令獲得第一項(xiàng)參數(shù):
代碼如下:
# cp anaconda-ks.cfg anaconda-ks.cfg.bak
anaconda-ks.cfg
# vi -5 !^
vi anaconda-ks.cfg
13.為特定的命令替換指定的參數(shù)
在下面的例子,!cp:2 從命令歷史中搜索以 cp 開頭的命令,并獲取它的第二項(xiàng)參數(shù):
代碼如下:
# cp ~/longname.txt /really/a/very/long/path/long-filename.txt
# ls -l !cp:2
ls -l /really/a/very/long/path/long-filename.txt
下例里,!cp:$ 獲取 cp 命令的最后一項(xiàng)參數(shù):
代碼如下:
# ls -l !cp:$
ls -l /really/a/very/long/path/long-filename.txt
14.使用 HISTSIZE 禁用 history
如果你想禁用 history,可以將 HISTSIZE 設(shè)置為 0:
代碼如下:
# export HISTSIZE=0
# history
# [Note that history did not display anything]
15.使用 HISTIGNORE 忽略歷史中的特定命令
下面的例子,將忽略 pwd、ls、ls -ltr 等命令:
代碼如下:
# export HISTIGNORE=”pwd:ls:ls -ltr:”
# pwd
# ls
# ls -ltr
# service httpd stop
# history | tail -3
79 export HISTIGNORE=”pwd:ls:ls -ltr:”
80 service httpd stop
81 history
[Note that history did not record pwd, ls and ls -ltr]
上面就是Linux下history命令的例子詳解了,從這15個(gè)例子中你能更深入的了解history命令的實(shí)際應(yīng)用,如果你經(jīng)常使用命令,相信history命令是你的好幫手。
發(fā)表評(píng)論
共0條
評(píng)論就這些咯,讓大家也知道你的獨(dú)特見解
立即評(píng)論以上留言僅代表用戶個(gè)人觀點(diǎn),不代表系統(tǒng)之家立場(chǎng)