① 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瀽镄勮瘽锛屽悗鏋滀笉鍫璁炬兂锛