{"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":"
\u5bfc\u8bfb<\/td>\n | Linux\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 |