① linux涓媓istory鍛戒護鏄劇ず鍘嗗彶鎸囦護璁板綍鐨勪嬌鐢ㄦ柟娉
History鍛戒護涓昏佺敤浜庢樉紺哄巻鍙叉寚浠よ板綍鍐呭, 涓嬭揪鍘嗗彶綰褰曚腑鐨勬寚浠 銆
1History鍛戒護璇娉錛
[test@linux]# history [n]
[test@linux]# history [-c]
[test@linux]# history [-raw] histfiles
鍙傛暟錛
n 錛氭暟瀛,瑕佸垪鍑烘渶榪戠殑 n 絎斿懡浠ゅ垪琛
-c 錛氬皢鐩鍓嶇殑shell涓鐨勬墍鏈 history 鍐呭瑰叏閮ㄦ秷闄
-a 錛氬皢鐩鍓嶆柊澧炵殑history 鎸囦護鏂板炲叆 histfiles 涓錛岃嫢娌℃湁鍔 histfiles 錛
鍒欓勮懼啓鍏 ~/.bash_history
-r 錛氬皢 histfiles 鐨勫唴瀹硅誨埌鐩鍓嶈繖涓 shell 鐨 history 璁板繂涓
-w 錛氬皢鐩鍓嶇殑 history 璁板繂鍐呭瑰啓鍏 histfiles
Linux緋葷粺褰撲綘鍦╯hell(鎺у埗鍙)涓杈撳叆騫舵墽琛屽懡浠ゆ椂錛宻hell浼氳嚜鍔ㄦ妸浣犵殑鍛戒護璁板綍鍒板巻鍙插垪琛ㄤ腑錛屼竴鑸淇濆瓨鍦ㄧ敤鎴風洰褰曚笅鐨.bash_history鏂囦歡涓銆傞粯璁や繚瀛1000鏉★紝浣犱篃鍙浠ユ洿鏀硅繖涓鍊箋
濡傛灉浣犻敭鍏 history, history浼氬悜浣犳樉紺轟綘鎵浣跨敤鐨勫墠1000涓鍘嗗彶鍛戒護錛屽苟涓旂粰瀹冧滑緙栦簡鍙鳳紝浣犱細鐪嬪埌涓涓鐢ㄦ暟瀛楃紪鍙風殑鍒楄〃蹇閫熶粠灞忓箷涓婂嵎榪囥備綘鍙鑳戒笉闇瑕佹煡鐪1000涓鍛戒護涓鐨勬墍鏈夐」鐩, 褰撶劧浣犱篃鍙浠ュ姞鍏ユ暟瀛楁潵鍒楀嚭鏈榪戠殑 n 絎斿懡浠ゅ垪琛ㄣ
linux涓環istory鍛戒護涓嶄粎浠呰╂垜浠鍙浠ユ煡璇㈠巻鍙插懡浠よ屽凡. 鎴戜滑榪樺彲浠ュ埄鐢ㄧ浉鍏崇殑鍔熻兘鏉ュ府鎴戜滑鎵ц屽懡浠ゃ
2榪愯岀壒瀹氱殑鍘嗗彶鍛戒護
history浼氬垪鍑篵ash淇濆瓨鐨勬墍鏈夊巻鍙插懡浠わ紝騫朵笖緇欏畠浠緙栦簡鍙鳳紝鎴戜滑鍙浠ヤ嬌鐢ㄢ滃徆鍙鋒帴緙栧彿鈥濈殑鏂瑰紡榪愯岀壒瀹氱殑鍘嗗彶鍛戒護.
璇娉曡存槑:
[test@linux]# [!number] [!command] [!!]
鍙傛暟璇存槑錛
number 錛氱鍑犱釜鎸囦護鐨勬剰鎬濓紱
command 錛氭寚浠ょ殑寮澶村嚑涓瀛楁瘝
! 錛氫笂涓涓鎸囦護鐨勬剰鎬濓紒
3History鍛戒護瀹炴垬
鍒楀嚭鎵鏈夌殑鍘嗗彶璁板綍錛
[test@linux] # history
鍙鍒楀嚭鏈榪10鏉¤板綍錛
[test@linux] # history 10 (娉,history鍜10涓闂存湁絀烘牸)
浣跨敤鍛戒護璁板綍鍙風爜鎵ц屽懡浠,鎵ц屽巻鍙叉竻鍗曚腑鐨勭99鏉″懡浠
[test@linux] #!99 (!鍜99涓闂存病鏈夌┖鏍)
閲嶅嶆墽琛屼笂涓涓鍛戒護
[test@linux] #!!
鎵ц屾渶鍚庝竴嬈′互rpm寮澶寸殑鍛戒護(!? ?浠h〃鐨勬槸瀛楃︿覆,榪欎釜String鍙浠ラ殢渚胯緭錛孲hell浼氫粠鏈鍚庝竴鏉″巻鍙插懡浠ゅ悜鍓嶆悳緔錛屾渶鍏堝尮閰嶇殑涓鏉″懡浠ゅ皢浼氬緱鍒版墽琛屻)
[test@linux] #!rpm
閫愬睆鍒楀嚭鎵鏈夌殑鍘嗗彶璁板綍錛
[test@linux]# history | more
絝嬪嵆娓呯┖history褰撳墠鎵鏈夊巻鍙插懡浠ょ殑璁板綍
[test@linux] #history -c
闄や簡浣跨敤history鍛戒護,鍦 shell 鎴 GUI 緇堢鎻愮ず涓嬶紝浣犱篃鍙浠ヤ嬌鐢ㄤ笂涓嬫柟鍚戦敭鏉ョ炕闃呭懡浠ゅ巻鍙(鍚戜笅綆澶翠細鍚戝墠緲婚槄)錛岀洿鍒頒綘鎵懼埌鎵闇鍛戒護涓烘銆傝繖鍙浠ヨ╂垜浠寰堟柟渚垮湴緙栬緫鍓嶉潰鐨勬煇涓鏉″懡浠わ紝鑰屼笉鐢ㄩ噸澶嶈緭鍏ョ被浼肩殑鍛戒護銆
History鍛戒護鐨勭敤閫旂『瀹炲緢澶э紒浣嗛渶瑕佸皬蹇冨畨鍏ㄧ殑闂棰!灝ゅ叾鏄 root 鐨勫巻鍙茬邯褰曟。妗堬紝榪欐槸榛戝浠鐨勬渶鐖憋紒鍥犱負涓嶅皬蹇冪殑 root 浼氬皢寰堝氱殑閲嶈佽祫鏂欏湪鎵ц岀殑榪囩▼涓浼氳綰褰曞湪 ~/.bash_history 褰撲腑錛屽傛灉榪欎釜妗f堣瑙f瀽鐨勮瘽錛屽悗鏋滀笉鍫璁炬兂錛