{"id":129066,"date":"2018-12-01T08:27:17","date_gmt":"2018-12-01T00:27:17","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=129066"},"modified":"2018-11-27T09:29:56","modified_gmt":"2018-11-27T01:29:56","slug":"linux-bash","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-bash.html","title":{"rendered":"\u6559\u4f60\u4e00\u4e9bLinux\u4e2d\u9690\u85cfbash\u5386\u53f2\u547d\u4ee4\u7684\u5c0f\u6280\u5de7"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5982\u679c\u4f60\u767b\u5f55\u8fc7 Linux \u7cfb\u7edf\uff0c\u5e76\u6572\u8fc7\u4e00\u4e9b\u547d\u4ee4\uff0c\u90a3\u4f60\u5e94\u8be5\u77e5\u9053\uff0cbash history \u4f1a\u8bb0\u5f55\u4f60\u8f93\u5165\u7684\u6240\u6709\u547d\u4ee4\u3002\u8fd9\u4e2a\u64cd\u4f5c\u5176\u5b9e\u662f\u6709\u4e00\u5b9a\u98ce\u9669\u7684\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u6211\u4e2a\u4eba\u7ecf\u5e38\u4f7f\u7528 Linux\uff0c\u6240\u4ee5\u6211\u60f3\u7740\u7814\u7a76\u4e00\u756a\uff0c\u770b\u770b\u5982\u4f55\u9690\u85cf bash history\u3002\u4e0b\u9762\u5c31\u662f\u6211\u6574\u7406\u7684\u4e00\u4e9b\u65b9\u6cd5\uff0c\u4ec5\u4f9b\u5927\u5bb6\u53c2\u8003\uff1a
\n\"\"<\/p>\n

\u00b7 exit normally \u2013 history \u8bb0\u5f55\u6b63\u5e38\u5199\u5165<\/p>\n

\u00b7 kill\u2013 \u670d\u52a1\u5668\u7aef\u8fd0\u884c -kill bash \u8fdb\u7a0bID\u540e\u5c31\u4e0d\u4f1a\u518d\u8bb0\u5f55 history \u4e86\u3002\u6211\u68c0\u67e5\u8fc7\u662f\u5426\u9700\u8981\u52a0-9\u53c2\u6570\uff0c\u4e0d\u8fc7\u4e0d\u7528\uff0c\u53ea\u9700\u8981\u4e00\u4e2a\u57fa\u672c\u7684 kill \u547d\u4ee4\uff0c\u5c31\u53ef\u4ee5\u6740\u6389\u8fdb\u7a0b\u5e76\u963b\u6b62\u5b83\u5199\u5165\u6587\u4ef6\u3002<\/p>\n

\u00b7kill \u2013 \u5ba2\u6237\u7aef\u8fd0\u884c\u2013kill ssh \u8fdb\u7a0b ID\uff0c\u5373\u65f6\u52a0\u4e86-9\u53c2\u6570\u8fd8\u662f\u4f1a\u6709\u5386\u53f2\u8bb0\u5f55\u3002<\/p>\n

\u00b7 set +o history\u2013 \u4e0d\u4f1a\u5c06\u4efb\u4f55\u5f53\u524d\u4f1a\u8bdd\u5199\u5165\u65e5\u5fd7\u3002\u53ef\u4ee5\u5728\u4f1a\u8bdd\u671f\u95f4\u4efb\u4f55\u65f6\u95f4\u8fd0\u884c\uff0c\u5e76\u9690\u85cf\u6240\u6709\u547d\u4ee4\u3002<\/p>\n

\u00b7 set -o history\u2013 \u91cd\u542f\u65e5\u5fd7\u8bb0\u5f55\uff0c\u4f46\u662f\u4f1a\u8bb0\u5f55 set \u547d\u4ee4\uff0c\u6240\u4ee5\u4f1a\u53d1\u751f\u4e00\u4e9b\u660e\u663e\u7684\u53d8\u5316\u3002<\/p>\n

\u00b7 unset HISTFILE \u2013 \u6e05\u9664\u8bb0\u5f55\u5386\u53f2\u6587\u4ef6\u4f4d\u7f6e\u7684\u53d8\u91cf\uff0c\u8fd9\u6837\u5c31\u4e0d\u4f1a\u5b58\u50a8\u4efb\u4f55\u4e1c\u897f<\/p>\n

\u00b7 history -c\u2013 \u5f7b\u5e95\u6e05\u9664\u5386\u53f2\u3002\u8fd9\u6761\u547d\u4ee4\u4f5c\u7528\u975e\u5e38\u660e\u663e\uff0c\u56e0\u4e3a\u6240\u6709\u7684\u5386\u53f2\u547d\u4ee4\u90fd\u6ca1\u4e86\u3002<\/p>\n

\u00b7 export HISTIGNORE=\u201cls*:cat*\u201d\u2013 \u8fd9\u6761\u547d\u4ee4\u662f\u4e0d\u8bb0\u5f55\u5f15\u53f7\u4e2d\u4ee5\u5192\u53f7\u4e3a\u5206\u9694\u7b26\u7684\u547d\u4ee4\u3002\u8fd9\u6761\u547d\u4ee4\u53ef\u4ee5\u4f7f\u7528shell\u6a21\u5f0f\uff0c\u6709\u70b9\u7c7b\u4f3c\u6b63\u5219\uff0c\u4f46\u4e0d\u5c3d\u76f8\u540c<\/p>\n

\u00b7 export HISTFILESIZE=10\u2013 \u8bbe\u7f6e\u5386\u53f2\u8bb0\u5f55\u6570\u91cf\u4e3a10\u3002\u5982\u679c\u4f60\u5df2\u7ecf\u5b8c\u6210\u4e86\u60f3\u8981\u9690\u85cf\u7684\u64cd\u4f5c\uff0c\u4f46\u53c8\u60f3\u4fdd\u7559\u5176\u4ed6\u7684\u547d\u4ee4\uff0c\u8bf7\u91cd\u65b0\u8ba1\u7b97\uff0c\u5c06\u8bb0\u5f55\u6570\u7684\u5927\u5c0f\u8bbe\u7f6e\u4e3a\u5c0f\u4e8e\u603b\u6570\u5e76\u7ee7\u7eed\u6267\u884c\u3002\u8fd9\u6837\uff0c\u6240\u6709\u4e4b\u524d\u7684\u547d\u4ee4\u5c31\u4f1a\u4e0d\u53ef\u89c1\uff0c\u770b\u8d77\u6765\u4f1a\u6709\u4e00\u4e9b\u53ef\u7591\uff0c\u4f46\u662f\u56e0\u4e3a\u5386\u53f2\u8bb0\u5f55\u4e2d\u8fd8\u662f\u6709\u5185\u5bb9\uff0c\u6240\u4ee5\u4eba\u4eec\u53ef\u80fd\u4e0d\u4f1a\u6ce8\u610f\u5230\u3002<\/p>\n

\u00b7 editing the.bash_history file\u2013 \u5982\u679c\u4f60\u5728\u4f1a\u8bdd\u671f\u95f4\u7f16\u8f91\u8fd9\u4e2a\u6587\u4ef6\uff0c\u7f16\u8f91\u7684\u5185\u5bb9\u5c06\u4f1a\u51fa\u73b0\u5728\u4f1a\u8bdd\u7684\u547d\u4ee4\u4e4b\u524d\uff0c\u8fd9\u6837\u4f60\u5176\u5b9e\u53ef\u4ee5\u5728 history \u4e2d\u6dfb\u52a0\u4e00\u4e9b\u4f60\u5b9e\u9645\u5e76\u6ca1\u6709\u8fd0\u884c\u8fc7\u7684\u547d\u4ee4\uff0c\u6240\u4ee5\u8fd9\u4e5f\u4e0d\u5931\u4e3a\u4e00\u4e2a\u597d\u529e\u6cd5\u3002<\/p>\n

\u00b7 using multiple sessions\u2013 \u4e00\u4e2a\u4f1a\u8bdd\u7ec8\u6b62\u65f6\u624d\u4f1a\u5199\u5165 bash history\u3002\u90a3\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e24\u4e2a\u4f1a\u8bdd\uff0c\u7b2c\u4e00\u4e2a\u4f1a\u8bdd\u7ec8\u6b62\u4f1a\u5199\u5165history\uff0c\u7136\u540e\u7b2c\u4e8c\u4e2a\u4f1a\u8bdd\u7684\u5185\u5bb9\u4f1a\u5728\u7b2c\u4e00\u4e2a\u4f1a\u8bdd\u7ec8\u6b62\u65f6\u624d\u5f00\u59cb\u5199\u5165 history<\/p>\n

\u00b7 putting a space before a command\uff08\u547d\u4ee4\u524d\u9762\u52a0\u4e00\u4e2a\u7a7a\u683c\uff09 \u2013 \u6839\u636e\u914d\u7f6e\uff0c\u5728\u547d\u4ee4\u524d\u52a0\u4e00\u4e2a\u7a7a\u683c\uff0c\u5c31\u4f1a\u4e0d\u8fdb\u884c\u8bb0\u5f55\u3002\u5982\u679c\u4f60\u5df2\u7ecf\u8f93\u5165\u4e86\u4f60\u4e0d\u60f3\u8bb0\u5f55\u7684\u547d\u4ee4\uff0c\u90a3\u4e48\u8fd9\u4e2a\u529f\u80fd\u5c31\u6ca1\u4ec0\u4e48\u7528\uff0c\u4f46\u5982\u679c\u60f3\u8ba9\u51e0\u6761\u597d\u4e0d\u76f8\u5173\u7684\u547d\u4ee4\u770b\u4f3c\u4e00\u6761\u7684\u8bdd\uff0c\u4f7f\u7528\u8fd9\u4e2a\u8fd8\u662f\u4e0d\u9519\u7684\u3002\u5728\u4f7f\u7528\u4e4b\u524d\u8bf7\u5148\u8fdb\u884c\u6d4b\u8bd5\uff0c\u56e0\u4e3a\u6839\u636e\u53d1\u884c\u7248\u548c\u7528\u6237\u914d\u7f6e\u4e0d\u540c\uff0c\u60c5\u51b5\u4f1a\u6709\u6240\u4e0d\u540c\u3002<\/p>\n

\u00b7 history -r\u2013 \u8fd9\u6761\u547d\u4ee4\u4f1a\u91cd\u65b0\u8bfb\u53d6 history \u6587\u4ef6\uff0c\u80fd\u591f\u5c06\u5386\u53f2\u8bb0\u5f55\u91cd\u7f6e\u4e3a\u4f60\u767b\u5f55\u65f6\u7684\u72b6\u6001\u3002\u8fd9\u6761\u547d\u4ee4\u4f3c\u4e4e\u975e\u5e38\u6709\u7528\uff0c\u5c24\u5176\u662f\u4f60\u53ef\u4ee5\u7f16\u8f91 history \u6587\u4ef6\uff0c\u6dfb\u52a0\u547d\u4ee4\u65f6\uff0c\u7136\u540e\u5173\u6389 shell\u3002\u8fd9\u4f1a\u5199\u5165\u7ecf\u8fc7\u4f60\u4fee\u6539\u7684 history\uff0c\u4e0d\u7559\u4efb\u4f55\u75d5\u8ff9\u3002<\/p>\n

\u4e0a\u9762\u8fd9\u4e9b\u547d\u4ee4\uff0c\u597d\u50cf\u201cset +o history\u201d\u662f\u6700\u597d\u7528\u7684\u4e5f\u662f\u6700\u901a\u7528\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u4f1a\u9690\u85cf\u5f53\u524d\u4f1a\u8bdd\u7684\u6240\u6709\u547d\u4ee4\uff0c\u4f46\u662f\u4f1a\u4fdd\u7559\u4e4b\u524d\u7684\u547d\u4ee4\u3002
\n\u4e0d\u8fc7\u6839\u636e\u573a\u666f\u4e0d\u540c\uff0c\u5176\u4ed6\u7684\u547d\u4ee4\u4e5f\u662f\u975e\u5e38\u6709\u6548\u7684\u3002<\/p>\n

\u5728\u4f60\u4f7f\u7528\u8fd9\u4e9b\u547d\u4ee4\u4e4b\u524d\uff0c\u4e00\u5b9a\u8981\u5148\u81ea\u5df1\u6d4b\u8bd5\u4e00\u904d\u3002\u5f53\u4f60\u5df2\u7ecf\u767b\u5f55\u4e86\u4e00\u4e2a\u7cfb\u7edf\uff0c\u800c\u4e14\u610f\u8bc6\u5230\u9700\u8981\u9690\u85cf\u67d0\u4e9b\u547d\u4ee4\u65f6\uff0c\u4e0d\u8981\u614c\u5f20\uff0chistory \u53ea\u4f1a\u5728\u4f1a\u8bdd\u7ed3\u675f\u65f6\u5199\u5165\uff0c\u6240\u4ee5\u53ea\u8981\u4f1a\u8bdd\u8fd8\u6ca1\u6709\u7ed3\u675f\uff0c\u4f60\u5c31\u53ef\u4ee5\u505c\u4e0b\u6765\u601d\u8003\uff0c\u600e\u4e48\u53bb\u9690\u85cf\u547d\u4ee4\uff0c\u5e0c\u671b\u672c\u6587\u7684\u5185\u5bb9\u80fd\u591f\u5e2e\u5230\u4f60\u3002<\/ssh><\/bash><\/p>\n","protected":false},"excerpt":{"rendered":"

\u6211\u4e2a\u4eba\u7ecf\u5e38\u4f7f\u7528 Linux\uff0c\u6240\u4ee5\u6211\u60f3\u7740\u7814\u7a76\u4e00\u756a\uff0c\u770b\u770b\u5982\u4f55\u9690\u85cf bash history\u3002\u4e0b\u9762\u5c31\u662f\u6211\u6574\u7406\u7684\u4e00\u4e9b\u65b9 […]<\/p>\n","protected":false},"author":1482,"featured_media":129071,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-129066","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\/129066","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\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=129066"}],"version-history":[{"count":6,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/129066\/revisions"}],"predecessor-version":[{"id":129119,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/129066\/revisions\/129119"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/129071"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=129066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=129066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=129066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}