{"id":214351,"date":"2021-03-31T10:19:41","date_gmt":"2021-03-31T02:19:41","guid":{"rendered":"https:\/\/gulass.cn\/?p=214351"},"modified":"2021-03-22T10:20:16","modified_gmt":"2021-03-22T02:20:16","slug":"linux-history-shell","status":"publish","type":"post","link":"https:\/\/gulass.cn\/linux-history-shell.html","title":{"rendered":"Linux\u7cfb\u7edf\u4e0b\u6d3b\u7528History\u547d\u4ee4"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nLinux\u7cfb\u7edf\u4e0b\u53ef\u901a\u8fc7history\u547d\u4ee4\u67e5\u770b\u7528\u6237\u6240\u6709\u7684\u5386\u53f2\u64cd\u4f5c\u8bb0\u5f55\uff0c\u5728\u5b89\u5168\u5e94\u6025\u54cd\u5e94\u4e2d\u8d77\u7740\u975e\u5e38\u91cd\u8981\u7684\u4f5c\u7528\uff0c\u4f46\u5728\u672a\u8fdb\u884c\u9644\u52a0\u914d\u7f6e\u60c5\u51b5\u4e0b\uff0chistory\u547d\u4ee4\u53ea\u80fd\u67e5\u770b\u7528\u6237\u5386\u53f2\u64cd\u4f5c\u8bb0\u5f55\uff0c\u5e76\u4e0d\u80fd\u533a\u5206\u7528\u6237\u4ee5\u53ca\u64cd\u4f5c\u65f6\u95f4\uff0c\u4e0d\u4fbf\u4e8e\u5ba1\u8ba1\u5206\u6790\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u5f53\u7136\uff0c\u4e00\u4e9b\u4e0d\u597d\u7684\u64cd\u4f5c\u4e60\u60ef\u4e5f\u53ef\u80fd\u901a\u8fc7\u547d\u4ee4\u5386\u53f2\u6cc4\u9732\u654f\u611f\u4fe1\u606f\u3002<\/p>\n

\u4e0b\u9762\u6211\u4eec\u6765\u4ecb\u7ecd\u5982\u4f55\u8ba9history\u65e5\u5fd7\u8bb0\u5f55\u66f4\u7ec6\u5316\uff0c\u66f4\u4fbf\u4e8e\u6211\u4eec\u5ba1\u8ba1\u5206\u6790\u3002<\/p>\n

1\u3001\u547d\u4ee4\u5386\u53f2\u8bb0\u5f55\u4e2d\u52a0\u65f6\u95f4<\/strong><\/span><\/div>\n

\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u6ca1\u6709\u547d\u4ee4\u6267\u884c\u65f6\u95f4\uff0c\u4e0d\u5229\u4e8e\u5ba1\u8ba1\u5206\u6790\u3002<\/p>\n

\"\"<\/p>\n

\u901a\u8fc7\u8bbe\u7f6eexport HISTTIMEFORMAT=\u2019\\%F \\%T \u2018\uff0c\u8ba9\u5386\u53f2\u8bb0\u5f55\u4e2d\u5e26\u4e0a\u547d\u4ee4\u6267\u884c\u65f6\u95f4\u3002<\/p>\n

\u6ce8\u610f\u201d\\%T\u201d\u548c\u540e\u9762\u7684\u201d\u2019\u201d\u4e4b\u95f4\u6709\u7a7a\u683c\uff0c\u4e0d\u7136\u67e5\u770b\u5386\u53f2\u8bb0\u5f55\u7684\u65f6\u5019\uff0c\u65f6\u95f4\u548c\u547d\u4ee4\u4e4b\u95f4\u6ca1\u6709\u5206\u5272\u3002<\/p>\n

\u8981\u4e00\u52b3\u6c38\u9038\uff0c\u8fd9\u4e2a\u914d\u7f6e\u53ef\u4ee5\u5199\u5728\/etc\/profile\u4e2d\uff0c\u5f53\u7136\u5982\u679c\u8981\u5bf9\u6307\u5b9a\u7528\u6237\u505a\u914d\u7f6e\uff0c\u8fd9\u4e2a\u914d\u7f6e\u53ef\u4ee5\u5199\u5728\/home\/\\$USER\/.bash_profile\u4e2d\u3002<\/p>\n

\u672c\u6587\u5c06\u4ee5\/etc\/profile\u4e3a\u4f8b\u8fdb\u884c\u6f14\u793a\u3002<\/p>\n

\"\"<\/p>\n

\u8981\u4f7f\u914d\u7f6e\u7acb\u5373\u751f\u6548\u8bf7\u6267\u884csource \/etc\/profile\uff0c\u6211\u4eec\u518d\u67e5\u770bhistory\u8bb0\u5f55\uff0c\u53ef\u4ee5\u770b\u5230\u8bb0\u5f55\u4e2d\u5e26\u4e0a\u4e86\u547d\u4ee4\u6267\u884c\u65f6\u95f4\u3002<\/p>\n

\"\"<\/p>\n

\u5982\u679c\u60f3\u8981\u5b9e\u73b0\u66f4\u7ec6\u5316\u7684\u8bb0\u5f55\uff0c\u6bd4\u5982\u767b\u9646\u8fc7\u7cfb\u7edf\u7684\u7528\u6237\u3001IP\u5730\u5740\u3001\u64cd\u4f5c\u547d\u4ee4\u4ee5\u53ca\u64cd\u4f5c\u65f6\u95f4\u4e00\u4e00\u5bf9\u5e94\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728\/etc\/profile\u91cc\u9762\u52a0\u5165\u4ee5\u4e0b\u4ee3\u7801\u5b9e\u73b0<\/p>\n

\r\nexport HISTTIMEFORMAT=\"\\%F \\%T`who \\-u am i 2>\/dev\/null| awk '{print $NF}'|sed \\-e 's\/[()]\/\/g'``whoami` \r\n<\/pre>\n

\u6ce8\u610f\u7a7a\u683c\u90fd\u662f\u5fc5\u987b\u7684\u3002<\/p>\n

\"\"<\/p>\n

\u4fee\u6539\/etc\/profile\u5e76\u52a0\u8f7d\u540e\uff0chistory\u8bb0\u5f55\u5982\u4e0b\uff0c\u65f6\u95f4\u3001IP\u3001\u7528\u6237\u53ca\u6267\u884c\u7684\u547d\u4ee4\u90fd\u4e00\u4e00\u5bf9\u5e94\u3002<\/p>\n

\"\"<\/p>\n

\u901a\u8fc7\u4ee5\u4e0a\u914d\u7f6e\uff0c\u6211\u4eec\u57fa\u672c\u4e0a\u53ef\u4ee5\u6ee1\u8db3\u65e5\u5e38\u7684\u5ba1\u8ba1\u5de5\u4f5c\u4e86\uff0c\u4f46\u4e86\u89e3\u7cfb\u7edf\u7684\u670b\u53cb\u5e94\u8be5\u5f88\u5bb9\u6613\u770b\u51fa\u6765\uff0c\u8fd9\u79cd\u65b9\u6cd5\u53ea\u662f\u8bbe\u7f6e\u4e86\u73af\u5883\u53d8\u91cf\uff0c\u653b\u51fb\u8005unset\u6389\u8fd9\u4e2a\u73af\u5883\u53d8\u91cf\uff0c\u6216\u8005\u76f4\u63a5\u5220\u9664\u547d\u4ee4\u5386\u53f2\uff0c\u5bf9\u4e8e\u5b89\u5168\u5e94\u6025\u6765\u8bf4\uff0c\u8fd9\u65e0\u7591\u662f\u4e00\u4e2a\u707e\u96be\u3002<\/p>\n

\u9488\u5bf9\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u6211\u4eec\u5e94\u8be5\u5982\u4f55\u5e94\u5bf9\uff0c\u4e0b\u9762\u624d\u662f\u6211\u4eec\u4eca\u5929\u7684\u91cd\u70b9\uff0c\u901a\u8fc7\u4fee\u6539bash\u6e90\u7801\uff0c\u8ba9history\u8bb0\u5f55\u901a\u8fc7syslog\u53d1\u9001\u5230\u8fdc\u7a0blogserver\u4e2d\uff0c\u5927\u5927\u589e\u52a0\u4e86\u653b\u51fb\u8005\u5bf9history\u8bb0\u5f55\u5b8c\u6574\u6027\u7834\u574f\u7684\u96be\u5ea6\u3002<\/p>\n

2\u3001\u4fee\u6539bash\u6e90\u7801\uff0c\u652f\u6301syslog\u8bb0\u5f55<\/strong><\/span><\/div>\n

\u9996\u5148\u4e0b\u8f7dbash\u6e90\u7801\uff0c\u53ef\u4ee5\u4ecegnu.org\u4e0b\u8f7d\uff0c\u8fd9\u91cc\u4e0d\u505a\u8be6\u7ec6\u8bf4\u660e\u4e86\uff0c\u7cfb\u7edf\u9700\u8981\u5b89\u88c5gcc\u7b49\u7f16\u8bd1\u73af\u5883\u3002\u6211\u4eec\u7528bash4.4\u7248\u672c\u505a\u6f14\u793a\u3002<\/p>\n

\u4fee\u6539\u6e90\u7801\uff1abashhist.c<\/p>\n

\"\"<\/p>\n

\u4fee\u6539\u6e90\u7801config-top.h\uff0c\u53d6\u6d88\/#define SYSLOG_HISTORY\/\u8fd9\u884c\u7684\u6ce8\u91ca<\/p>\n

\"\"<\/p>\n

\u7f16\u8bd1\u5b89\u88c5\uff0c\u7f16\u8bd1\u8fc7\u7a0b\u4e0d\u505a\u8be6\u7ec6\u8bf4\u660e\uff0c\u672c\u6587\u4e2d\u4f7f\u7528\u7684\u7f16\u8bd1\u53c2\u6570\u4e3a\uff1a .\/configure --prefix=\/usr\/local\/bash\uff0c\u5b89\u88c5\u6210\u529f\u540e\u5bf9\u5e94\u76ee\u5f55\u5982\u4e0b\uff1a<\/p>\n

\"\"<\/p>\n

\u6b64\u65f6\u53ef\u4ee5\u4fee\u6539\/etc\/passwd\u4e2d\u7528\u6237shell\u73af\u5883\uff0c\u4e5f\u53ef\u4ee5\u7528\u7f16\u8bd1\u597d\u7684\u6587\u4ef6\u76f4\u63a5\u66ff\u6362\u539f\u6709\u7684bash\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u4f46\u6700\u597d\u5bf9\u539f\u6587\u4ef6\u505a\u597d\u5907\u4efd\u3002<\/p>\n

\u66ff\u6362\u65f6\u8981\u6ce8\u610f\u4e24\u70b9:<\/p>\n

1\u3001\u4e00\u5b9a\u8981\u7ed9\u53ef\u6267\u884c\u6743\u9650\uff0c\u9ed8\u8ba4\u662f\u6709\u7684\uff0c\u4e0d\u8fc7\u6709\u65f6\u5019\u4e0b\u8f7d\u5230windows\u7cfb\u7edf\u540e\uff0c\u518d\u4e0a\u4f20\u5c31\u6ca1\u6709\u53ef\u6267\u884c\u6743\u9650\u4e86\uff0c\u8fd9\u91cc\u4e00\u5b9a\u8981\u786e\u5b9a\uff0c\u4e0d\u7136\u4f60\u4f1a\u540e\u6094\u7684\uff1b<\/p>\n

2\u3001\u66ff\u6362\u65f6\u539fbash\u88ab\u5360\u7528\uff0c\u53ef\u4ee5\u4fee\u6539\u539f\u7528\u6237\u7684bash\u73af\u5883\u540e\u518d\u8fdb\u884c\u66ff\u6362\u3002<\/p>\n

\u67e5\u770b\u6548\u679c\uff0c\u6211\u4eec\u53d1\u73b0history\u8bb0\u5f55\u5df2\u7ecf\u5199\u5230\u4e86\/var\/log\/message\u4e2d\u3002<\/p>\n

\"\"<\/p>\n

\u5982\u679c\u8981\u5199\u5230\u8fdc\u7a0blogserver\uff0c\u9700\u8981\u914d\u7f6esyslog\u670d\u52a1\uff0c\u5177\u4f53\u914d\u7f6e\u8fd9\u91cc\u4e0d\u505a\u8be6\u7ec6\u8bb2\u89e3\uff0c\u5927\u5bb6\u81ea\u5df1\u7814\u7a76\uff0c\u53d1\u9001\u5230\u8fdc\u7aeflogserver\u6548\u679c\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n

\"\"<\/p>\n

\u901a\u8fc7\u4ee5\u4e0a\u624b\u6bb5\uff0c\u53ef\u4ee5\u6709\u6548\u4fdd\u8bc1history\u8bb0\u5f55\u7684\u5b8c\u6574\u6027\uff0c\u907f\u514d\u653b\u51fb\u8005\u767b\u5f55\u7cfb\u7edf\u540e\uff0c\u901a\u8fc7\u53d6\u6d88\u73af\u5883\u53d8\u91cf\u3001\u5220\u9664history\u8bb0\u5f55\u7b49\u65b9\u5f0f\u62b9\u6389\u64cd\u4f5c\u884c\u4e3a\uff0c\u4e3a\u5b89\u5168\u5ba1\u8ba1\u3001\u5e94\u6025\u54cd\u5e94\u7b49\u63d0\u4f9b\u4e86\u5b8c\u6574\u7684\u539f\u59cb\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5f53\u7136\uff0c\u4e00\u4e9b\u4e0d\u597d\u7684\u64cd\u4f5c\u4e60\u60ef\u4e5f\u53ef\u80fd\u901a\u8fc7\u547d\u4ee4\u5386\u53f2\u6cc4\u9732\u654f\u611f\u4fe1\u606f\u3002 \u4e0b\u9762\u6211\u4eec\u6765\u4ecb\u7ecd\u5982\u4f55\u8ba9history\u65e5\u5fd7\u8bb0\u5f55\u66f4\u7ec6\u5316\uff0c\u66f4 […]<\/p>\n","protected":false},"author":1479,"featured_media":214353,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-214351","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/214351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=214351"}],"version-history":[{"count":2,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/214351\/revisions"}],"predecessor-version":[{"id":214366,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/214351\/revisions\/214366"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/214353"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=214351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=214351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=214351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}