{"id":263404,"date":"2023-03-07T08:44:54","date_gmt":"2023-03-07T00:44:54","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=263404"},"modified":"2023-02-03T23:45:51","modified_gmt":"2023-02-03T15:45:51","slug":"linux-history-commands","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-history-commands.html","title":{"rendered":"\u200b\u200b\u5728Linux\u4e2d\u600e\u6837\u4f7f\u7528history\u547d\u4ee4\u200b\u200b\uff1f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4f7f\u7528 Linux \u547d\u4ee4\u884c\u5de5\u4f5c\uff0c\u9700\u8981\u4e86\u89e3\u4e14\u4f7f\u7528 history \u7684\u4e00\u4e9b\u5e38\u7528\u7684\u7279\u6027\uff0c\u4e0d\u7ba1\u662f Linux \u521d\u5b66\u8005\uff0c\u8fd8\u662f\u7cfb\u7edf\u4e13\u5bb6\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5728\u4f7f\u7528\u8fc7\u4e00\u6bb5\u65f6\u95f4 Linux \u7ec8\u7aef\u4e4b\u540e\uff0c\u5927\u5bb6\u5e94\u8be5\u90fd\u4f1a\u6ce8\u610f\u5230\uff0c\u4f7f\u7528\u4e0a\u4e0b\u7bad\u5934\u6309\u952e\uff0c\u53ef\u4ee5\u6267\u884c\u4e4b\u524d\u8fd0\u884c\u8fc7\u7684\u547d\u4ee4\uff0c\u8fd9\u5c31\u662f history \u6240\u8d77\u5230\u7684\u4f5c\u7528\u3002<\/p>\n

1\uff0c\u67e5\u770b bash \u5386\u53f2\u8bb0\u5f55\uff08history\uff09<\/strong><\/div>\n

\u6211\u4eec\u5728\u4e4b\u524d\u7684\u6587\u7ae0\u4e2d\u4ecb\u7ecd\u8fc7 history \u7684\u4f7f\u7528\uff0c\u5927\u5bb6\u611f\u5174\u8da3\u53ef\u4ee5\u53c2\u8003\uff1a<\/p>\n

\u67e5\u770b bash \u5386\u53f2\u8bb0\u5f55\uff0c\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u5c31\u662f\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165 history \u547d\u4ee4\uff1a<\/p>\n

history<\/pre>\n

\u8fd9\u5c06\u663e\u793a\u4f60\u5386\u53f2\u8bb0\u5f55\u4e2d\u7684\u4e0a\u767e\u6216\u4e0a\u5343\u6761\u547d\u4ee4\uff0c\u8fd9\u53d6\u51b3\u4e8e\u00a0HISTSIZE\u00a0\u53d8\u91cf\u4e2d\u8bbe\u5b9a\u7684\u5927\u5c0f\u3002<\/p>\n

\"\"<\/p>\n

\u5982\u679c\u4e0d\u60f3\u5217\u51fa\u6240\u6709\u7684\u5386\u53f2\u8bb0\u5f55\uff0c\u53ef\u4ee5\u9650\u5236\u663e\u793a\u51fa\u7684\u8bb0\u5f55\u6761\u6570\u3002\u6bd4\u5982\uff0c\u60f3\u8981\u53ea\u663e\u793a\u6700\u8fd1\u7684 7 \u6761\u5386\u53f2\u547d\u4ee4\uff0c\u53ef\u5728 history \u547d\u4ee4\u540e\u8ddf\u4e0a\u4e00\u4e2a\u6570\u5b57 7\uff0c\u5982\u4e0b\uff1a<\/p>\n

history 7<\/pre>\n

\"\"<\/p>\n

2\uff0c\u8fd0\u884c bash \u5386\u53f2\u8bb0\u5f55\u4e2d\u7684\u547d\u4ee4<\/strong><\/div>\n

\u5728\u67e5\u770b history \u8bb0\u5f55\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u611f\u53f9\u53f7 ! \u6765\u8fd0\u884c\u5176\u4e2d\u7684\u67d0\u6761\u5386\u53f2\u547d\u4ee4\uff0c\u5982\u4e0b\u65b9\u5f0f\uff1a<\/p>\n

! <HISTORY NUMBER><\/pre>\n

\"\"<\/p>\n

\u4f7f\u7528\u4e24\u4e2a\u611f\u53f9\u53f7\u00a0!!\u00a0\u53ef\u4ee5\u8fd4\u56de\u5386\u53f2\u8bb0\u5f55\u4e2d\u6700\u540e\u7684\u4e00\u6761\u547d\u4ee4\u3002\u6bd4\u5982\uff1a<\/p>\n

sudo !!<\/pre>\n

\"\"<\/p>\n

\u53e6\u5916\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u7279\u5b9a\u7684\u5b57\u7b26\u4e32\u6765\u8fd0\u884c history \u547d\u4ee4\uff0c\u8fd9\u4e2a\u201c\u7279\u5b9a\u7684\u5b57\u7b26\u4e32\u201d\u5c31\u662f history \u547d\u4ee4\u4e2d\uff0c\u4e0e\u5176\u5339\u914d\u7684\u547d\u4ee4\uff1a<\/p>\n

!text<\/pre>\n

\u6bd4\u5982\uff0c\u4f60\u66fe\u7ecf\u8fd0\u884c\u8fc7 echo $HISTCONTROL\uff0c\u7136\u540e\u60f3\u518d\u6b21\u8fd0\u884c\u5b83\uff0c\u90a3\u4e48\u53ef\u4ee5\u8fd9\u6837\uff1a<\/p>\n

!echo<\/pre>\n

\u4e0a\u8ff0\u547d\u4ee4\uff0c\u4f1a\u518d\u6b21\u8fd0\u884c history \u4e2d\u7684\u6700\u540e\u4e00\u6761 echo \u547d\u4ee4\uff1a<\/p>\n

\"\"<\/p>\n

\u8fd9\u5176\u5b9e\u4e5f\u76f8\u5f53\u4e8e\u662f\u5728 history \u547d\u4ee4\u4e2d\u4ee5 \u201c\u5b57\u7b26\u4e32\u201d \u65b9\u5f0f\u5339\u914d\u641c\u7d22\u3002<\/p>\n

\u5982\u679c\u4f60\u4e0d\u786e\u5b9a\u5728 history \u4e2d\u7684\u5177\u4f53\u547d\u4ee4\uff0c\u53ef\u4ee5\u5728\u5176\u540e\u6dfb\u52a0\u00a0:p\u00a0\u6765\u6253\u5370\u8be5\u547d\u4ee4\uff0c\u800c\u4e0d\u662f\u8fd0\u884c\uff0c\u6bd4\u5982\u00a0!echo:p\uff0c!23:p\u00a0\u7b49\u3002<\/p>\n

3\uff0c\u641c\u7d22 history \u8bb0\u5f55<\/strong><\/div>\n

\u4f60\u53ef\u80fd\u4f1a\u60f3\u5230\u4f7f\u7528\u200b\u200b\u00a0grep\u200b\u200b \u641c\u7d22 history \u8bb0\u5f55\uff0c\u50cf\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n

history | grep text<\/pre>\n

\u641c\u7d22\u5386\u53f2\u8bb0\u5f55\u7684\u4e00\u4e2a\u66f4\u597d\u4e14\u8d85\u7ea7\u65b9\u4fbf\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u00a0ctrl + r\u00a0\u952e\uff0c\u53cd\u5411\u641c\u7d22\u5e76\u952e\u5165\u60a8\u8981\u67e5\u627e\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n

\u53ef\u4ee5\u901a\u8fc7\u53cd\u590d\u6309\u00a0ctrl + r\u00a0\u6765\u5faa\u73af\u9009\u62e9\uff0c\u5f53\u627e\u5230\u8981\u67e5\u627e\u7684\u547d\u4ee4\u65f6\uff0c\u6309\u00a0ctrl + o\u00a0\u6216\u53ea\u6309\u00a0enter\u00a0\u952e\u5373\u53ef\u9009\u62e9\u5e76\u8fd0\u884c\u8be5\u547d\u4ee4\u3002<\/p>\n

\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u793a\u4f8b\u641c\u7d22\u5305\u542b \u201caud\u201d \u7684\u547d\u4ee4\uff1a<\/p>\n

\"\"<\/p>\n

\u5982\u679c\u627e\u4e0d\u5230\u60f3\u8981\u7684\u547d\u4ee4\uff0c\u53ef\u66f4\u6539\u641c\u7d22\u7684\u5b57\u7b26\u4e32\uff0c\u6216\u8005\u6309\u00a0ctrl + g\u00a0\u9000\u51fa\u641c\u7d22\u3002<\/p>\n

4\uff0c\u91cd\u65b0\u4f7f\u7528\u5386\u53f2\u8bb0\u5f55\u4e2d\u4ee5\u524d\u547d\u4ee4\u4e2d\u7684\u53c2\u6570<\/strong><\/div>\n

\u5173\u4e8e history \u7684\u53e6\u5916\u4e00\u4e2a\u5f88\u6709\u7528\u7684\u6280\u5de7\u662f\uff0c\u53ef\u4ee5\u5728\u65b0\u547d\u4ee4\u4e2d\u4f7f\u7528\u4ee5\u524d\u547d\u4ee4\u4e2d\u7684\u53c2\u6570\u3002<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u50cf\u8fd9\u6837\u4f7f\u7528\u4e0a\u4e00\u4e2a\u547d\u4ee4\u7684\u6700\u540e\u4e00\u4e2a\u53c2\u6570\uff1a<\/p>\n

<new command> !$<\/pre>\n

\u4e0a\u9762\u7684\u9009\u9879\u53ea\u63d0\u4f9b\u4e0a\u4e00\u4e2a\u547d\u4ee4\u7684\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u3002\u5982\u679c\u9700\u8981\u6240\u6709\u53c2\u6570\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

<new command> !*<\/pre>\n
5\uff0c\u6e05\u9664\u5386\u53f2\u8bb0\u5f55\u4e2d\u7684\u6761\u76ee<\/strong><\/div>\n

\u6709\u4e00\u4e2a\u540d\u4e3a HISTCONTROL\u00a0\u00a0\u7684\u73af\u5883\u53d8\u91cf\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5904\u7406 bash \u5386\u53f2\u8bb0\u5f55\u4e2d\u7684\u5197\u4f59\u6761\u76ee\u3002\u53ef\u4ee5\u4e3a\u5176\u6307\u5b9a\u4ee5\u4e0b\u4e09\u4e2a\u503c\u4e4b\u4e00\uff1a<\/p>\n

    \n
  • ignorespace\uff1a\u4f7f\u7528\u8fd9\u4e2a\u53d8\u91cf\u503c\uff0c\u5728\u8fd0\u884c\u67d0\u4e2a\u547d\u4ee4\u65f6\uff0c\u5728\u8be5\u547d\u4ee4\u524d\u9762\u52a0\u4e00\u4e2a\u7a7a\u683c\uff0c\u8be5\u547d\u4ee4\u7167\u5e38\u8fd0\u884c\uff0c\u4f46\u662f\u4e0d\u4f1a\u8bb0\u5f55\u5728 history \u8bb0\u5f55\u4e2d\uff1b<\/li>\n
  • ignoredups\uff1a\u5982\u679c\u6709\u4e24\u4e2a\u6216\u591a\u4e2a\u76f8\u540c\u7684\u547d\u4ee4\u8fde\u7eed\u8fd0\u884c\uff0c\u5219\u53ea\u6709\u4e00\u4e2a\u547d\u4ee4\u4f1a\u8bb0\u5f55\u5728 history \u8bb0\u5f55\u4e2d\uff1b<\/li>\n
  • ignoreboth\uff1a\u8bbe\u7f6e\u4e0a\u8ff0\u4e24\u4e2a\u529f\u80fd\u3002<\/li>\n<\/ul>\n

    \u8bbe\u7f6e HISTCONTROL\u00a0 \u53d8\u91cf\uff0c\u5e94\u8be5\u5728\u00a0bashrc\u00a0\u6587\u4ef6\u4e2d\u8bbe\u7f6e\uff0c\u4ee5\u4fbf\u5728\u6bcf\u6b21\u4f7f\u7528 bash shell \u65f6\u8be5\u53d8\u91cf\u7684\u8bbe\u7f6e\u90fd\u4f1a\u8d77\u4f5c\u7528\u3002<\/p>\n

    \u5982\u679c history \u4e2d\u7684\u8bb0\u5f55\u592a\u591a\uff0c\u53ef\u4ee5\u4f7f\u7528 -c \u9009\u9879\u6765\u6e05\u7406\u5386\u53f2\u8bb0\u5f55\uff0c\u7136\u540e\u4ece\u65b0\u5f00\u59cb\u8bb0\u5f55\u65b0\u7684\u547d\u4ee4\u3002<\/p>\n

    history -c<\/pre>\n

    \"\"<\/p>\n

    \u9664\u4e86\u6211\u4eec\u4e0a\u9762\u4ecb\u7ecd\u7684\u4ee5\u5916\uff0chistory \u8fd8\u6709\u5f88\u591a\u4e1c\u897f\u503c\u5f97\u7814\u7a76\u5b66\u4e60\uff0c\u5927\u5bb6\u53ef\u4ee5\u53c2\u8003 history \u547d\u4ee4\u7684 man \u624b\u518c\uff0c\u611f\u5174\u8da3\u7684\u8bdd\u8fd8\u53ef\u4ee5\u4e86\u89e3\u4e00\u4e0b\u00a0\u00a0history builtins\uff0c\u5730\u5740\u4e3a\uff1a<\/p>\n

    \u200b\u200bhttps:\/\/www.gnu.org\/software\/bash\/manual\/html_node\/Bash-History-Builtins.html<\/p>\n","protected":false},"excerpt":{"rendered":"

    \u5728\u4f7f\u7528\u8fc7\u4e00\u6bb5\u65f6\u95f4 Linux \u7ec8\u7aef\u4e4b\u540e\uff0c\u5927\u5bb6\u5e94\u8be5\u90fd\u4f1a\u6ce8\u610f\u5230\uff0c\u4f7f\u7528\u4e0a\u4e0b\u7bad\u5934\u6309\u952e\uff0c\u53ef\u4ee5\u6267\u884c\u4e4b\u524d\u8fd0\u884c\u8fc7\u7684\u547d\u4ee4\uff0c\u8fd9\u5c31\u662f […]<\/p>\n","protected":false},"author":323,"featured_media":262835,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-263404","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/263404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/323"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=263404"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/263404\/revisions"}],"predecessor-version":[{"id":263412,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/263404\/revisions\/263412"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/262835"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=263404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=263404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=263404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}