看板 Linux 關於我們 聯絡資訊
想如何快速尋找,已經下過的指令。 不好意思,是一個很古老的問題。 我們知道在 shell 裡面,通常都會記憶已打過的指令, 甚至登出之後,還會紀錄到 .bash_history 像這一類的檔案裡面, 以便下一次登錄後可以使用。使用方式通常都是按 『向上』鍵,就可以一個一個找。 雖然 shell 操作介面都很快,不過一個一個找還是挺沒效率的。 ------ 請問:若我要找『我曾經下過的指令』並且『以 export 開始的指令』 請問如何操作? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.25.13.212
mp607:grep export .bash_history 這樣? 12/07 22:33
shinja:!export 12/07 22:34
shinja:上面是會執行最近一次的export 指令,如果要執行更早之前的 12/07 22:42
shinja:export 指令可能要借助history 12/07 22:42
kiani:ctrl+r (輸入export) (再按ctrl+r 選擇) 12/07 22:47
kdjf:egrep '^export' .bash_history 12/07 22:47
asimon:cat .bash_history|grep export 12/07 23:49
Jerr:$ history | grep export # history 就是 bash history 12/07 23:53
johnjohnlin:ctrl+r +1 12/08 11:32
DrHydra:ctrl+r +1 超好用的 12/08 14:23
pgychen:linux 果然臥虎藏龍,這麼古老的問題,都這麼多人會。 12/08 21:34
johnjohnlin:我只是在回 ptt 水球時按錯視窗發現的XD 12/08 23:42
in3:ctrl+r 再輸入e 01/16 16:33