国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Linux > 正文

關(guān)于history的Linux命令行

2024-06-28 13:23:21
字體:
供稿:網(wǎng)友
關(guān)于history的linux命令行

1、使用 HISTTIMEFORMAT 顯示時間戳當(dāng)你從命令行執(zhí)行 history 命令后,通常只會顯示已執(zhí)行命令的序號和命令本身。如果你想要查看命令歷史的時間戳,那么可以執(zhí)行:

# export HISTTIMEFORMAT='%F %T '# history | more1 2008-08-05 19:02:39 service network restart2 2008-08-05 19:02:39 exit3 2008-08-05 19:02:39 id4 2008-08-05 19:02:39 cat /etc/redhat-release

使用 Ctrl+R 搜索歷史Ctrl+R 是我經(jīng)常使用的一個快捷鍵。此快捷鍵讓你對命令歷史進行搜索,對于想要重復(fù)執(zhí)行某個命令的時候非常有用。當(dāng)找到命令后,通常再按回車鍵就可以執(zhí)行該命令。如果想對找到的命令進行調(diào)整后再執(zhí)行,則可以按一下左或右方向鍵。

# [PRess Ctrl+R from the command prompt, which will display the reverse-i-search prompt](reverse-i-search)`red‘: cat /etc/redhat-release[Note: Press enter when you see your command, which will execute the command from the history]# cat /etc/redhat-releaseFedora release 9 (Sulphur)

快速重復(fù)執(zhí)行上一條命令有 4 種方法可以重復(fù)執(zhí)行上一條命令:

使用上方向鍵,并回車執(zhí)行。按 !! 并回車執(zhí)行。輸入 !-1 并回車執(zhí)行。按 Ctrl+P 并回車執(zhí)行。從命令歷史中執(zhí)行一個指定的命令在下面的例子中,如果你想重復(fù)執(zhí)行第 4 條命令,那么可以執(zhí)行 !4:

# history | more1 service network restart2 exit3 id4 cat /etc/redhat-release# !4cat /etc/redhat-releaseFedora release 9 (Sulphur)

通過指定關(guān)鍵字來執(zhí)行以前的命令在下面的例子,輸入 !ps 并回車,將執(zhí)行以 ps 打頭的命令:

# !psps aux | grep yproot 16947 0.0 0.1 36516 1264 ? Sl 13:10 0:00 ypbindroot 17503 0.0 0.0 4124 740 pts/0 S+ 19:19 0:00 grep yp

使用 HISTSIZE 控制歷史命令記錄的總行數(shù)將下面兩行內(nèi)容追加到 .bash_profile 文件并重新登錄 bash shell,命令歷史的記錄數(shù)將變成 450 條:

# vi ~/.bash_profileHISTSIZE=450HISTFILESIZE=450

使用 HISTFILE 更改歷史文件名稱默認情況下,命令歷史存儲在 ~/.bash_history 文件中。添加下列內(nèi)容到 .bash_profile 文件并重新登錄 bash shell,將使用 .commandline_warrior 來存儲命令歷史:

# vi ~/.bash_profileHISTFILE=/root/.commandline_warrior

使用 HISTCONTROL 從命令歷史中剔除連續(xù)重復(fù)的條目在下面的例子中,pwd 命令被連續(xù)執(zhí)行了三次。執(zhí)行 history 后你會看到三條重復(fù)的條目。要剔除這些重復(fù)的條目,你可以將 HISTCONTROL 設(shè)置為 ignoredups:

# pwd# pwd# pwd# history | tail -444 pwd45 pwd46 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 -356 export HISTCONTROL=ignoredups57 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

使用 HISTCONTROL 清除整個命令歷史中的重復(fù)條目上例中的 ignoredups 只能剔除連續(xù)的重復(fù)條目。要清除整個命令歷史中的重復(fù)條目,可以將 HISTCONTROL 設(shè)置成 erasedups:

# export HISTCONTROL=erasedups# pwd# service httpd stop# history | tail -338 pwd39 service httpd stop40 history | tail -3# ls -ltr# service httpd stop# history | tail -635 export HISTCONTROL=erasedups36 pwd37 history | tail -338 ls -ltr39 service httpd stop[Note that the previous service httpd stop after pwd got erased]40 history | tail -6

使用 HISTCONTROL 強制 history 不記住特定的命令將 HISTCONTROL 設(shè)置為 ignorespace,并在不想被記住的命令前面輸入一個空格:

# 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 -367 ls -ltr68 pwd69 history | tail -3使用 -c 選項清除所有的命令歷史如果你想清除所有的命令歷史,可以執(zhí)行:

# history -c

命令替換在下面的例子里,!!:$ 將為當(dāng)前的命令獲得上一條命令的參數(shù):

# ls anaconda-ks.cfganaconda-ks.cfg# vi !!:$vi anaconda-ks.cfg

下例中,!^ 從上一條命令獲得第一項參數(shù):

# cp anaconda-ks.cfg anaconda-ks.cfg.bakanaconda-ks.cfg# vi -5 !^vi anaconda-ks.cfg

為特定的命令替換指定的參數(shù)在下面的例子,!cp:2 從命令歷史中搜索以 cp 開頭的命令,并獲取它的第二項參數(shù):

# cp ~/longname.txt /really/a/very/long/path/long-filename.txt# ls -l !cp:2ls -l /really/a/very/long/path/long-filename.txt

下例里,!cp:$ 獲取 cp 命令的最后一項參數(shù):

# ls -l !cp:$ls -l /really/a/very/long/path/long-filename.txt

使用 HISTSIZE 禁用 history如果你想禁用 history,可以將 HISTSIZE 設(shè)置為 0:

# export HISTSIZE=0# history# [Note that history did not display anything]

使用 HISTIGNORE 忽略歷史中的特定命令下面的例子,將忽略 pwd、ls、ls -ltr 等命令:

# export HISTIGNORE=”pwd:ls:ls -ltr:”# pwd# ls# ls -ltr# service httpd stop# history | tail -379 export HISTIGNORE=”pwd:ls:ls -ltr:”80 service httpd stop81 history[Note that history did not record pwd, ls and ls -ltr]


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 汕尾市| 大宁县| 平南县| 永泰县| 绥中县| 吉水县| 泾阳县| 深州市| 泽普县| 会同县| 宝丰县| 阆中市| 南丹县| 固阳县| 邛崃市| 鹿泉市| 东莞市| 呼玛县| 长宁区| 西华县| 磐石市| 枝江市| 拉孜县| 巴林左旗| 全椒县| 拉孜县| 蓝田县| 沁水县| 承德县| 宁海县| 潜山县| 突泉县| 南涧| 府谷县| 松潘县| 牡丹江市| 始兴县| 高邑县| 武宁县| 隆德县| 含山县|