{"id":193643,"date":"2020-06-17T10:07:36","date_gmt":"2020-06-17T02:07:36","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=193643"},"modified":"2020-06-10T10:08:23","modified_gmt":"2020-06-10T02:08:23","slug":"linux-tail-example","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-tail-example.html","title":{"rendered":"Linux\u4e2dtail\u547d\u4ee4\u5b9e\u4f8b"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\ntail\u547d\u4ee4\u5c06\u6bcf\u4e2a\u6587\u4ef6\u7684\u6700\u540e10\u884c\u6253\u5370\u5230\u6807\u51c6\u8f93\u51fa\u3002\u5bf9\u4e8e\u591a\u4e2a\u6587\u4ef6\uff0c\u5728\u6bcf\u4e2a\u6587\u4ef6\u524d\u9762\u52a0\u4e0a\u4e00\u4e2a\u7ed9\u51fa\u6587\u4ef6\u540d\u7684\u5934\u3002\u5982\u679c\u6ca1\u6709\u6587\u4ef6\uff0c\u6216\u8005\u6587\u4ef6\u4e3a-<\/code>\uff0c\u5219\u8bfb\u53d6\u6807\u51c6\u8f93\u5165\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u5982\u4f55\u4f7f\u7528tail\u547d\u4ee4<\/strong><\/div>\n

\u4f7f\u7528tail<\/code>\u547d\u4ee4\u67e5\u770byum.log\u65e5\u5fd7\u6587\u4ef6\uff0c\u663e\u793a\u6700\u540e10\u884c\u5185\u5bb9\uff0ctail\u9ed8\u8ba4\u663e\u793a\u95ee\u4ef7\u4f60\u7684\u6700\u540e10\u884c\u5185\u5bb9\uff1a<\/p>\n

\r\n[root@localhost ~]# tail \/var\/log\/yum.log \r\nMay 26 15:22:08 Installed: pytalloc-2.1.16-1.el7.x86_64\r\nMay 26 15:22:08 Updated: libwbclient-4.10.4-11.el7_8.x86_64\r\nMay 26 15:22:08 Installed: samba-libs-4.10.4-11.el7_8.x86_64\r\nMay 26 15:22:08 Updated: samba-common-libs-4.10.4-11.el7_8.x86_64\r\nMay 26 15:22:08 Updated: samba-client-libs-4.10.4-11.el7_8.x86_64\r\nMay 26 15:22:08 Updated: libsmbclient-4.10.4-11.el7_8.x86_64\r\nMay 26 15:22:08 Installed: libarchive-3.1.2-14.el7_7.x86_64\r\nMay 26 15:22:09 Installed: samba-client-4.10.4-11.el7_8.x86_64\r\nMay 26 17:22:44 Installed: lm_sensors-libs-3.4.0-8.20160601gitf9185e5.el7.x86_64\r\nMay 26 17:22:44 Installed: sysstat-10.1.5-19.el7.x86_64\r\n<\/pre>\n

\"\"<\/p>\n

\u5982\u4f55\u663e\u793a\u6307\u5b9a\u7684\u884c\u6570<\/strong><\/div>\n

\u4f7f\u7528-n<\/code>\u547d\u4ee4\u663e\u793a\u6307\u5b9a\u7684\u884c\u6570\uff0c\u4e5f\u53ef\u4ee5\u7701\u7565\u5b57\u6bcdn<\/code>\uff0c\u53ea\u4f7f\u7528-<\/code>\u548c\u6570\u5b57(\u6570\u5b57\u548c-<\/code>\u4e4b\u95f4\u6ca1\u6709\u7a7a\u683c)\u3002<\/p>\n

\u4f8b\u5982\uff1a\u67e5\u770b\u81ea\u5df1\u521b\u5efa\u7684\u7528\u6237\uff0c\u67e5\u770b\/etc\/passwd<\/code>\u6587\u4ef6\u6700\u540e\u4e24\u884c\u5185\u5bb9\uff1a<\/p>\n

\r\n[root@localhost ~]# tail -2 \/etc\/passwd\r\nbob:x:1000:1001::\/home\/bob:\/bin\/bash\r\nuser01:x:1001:1002::\/home\/user01:\/bin\/bash\r\n<\/pre>\n

\"\"<\/p>\n

\u5982\u4f55\u5b9e\u65f6\u76d1\u63a7\u6587\u4ef6\u7684\u66f4\u6539<\/strong><\/div>\n

\u5982\u679c\u9700\u8981\u76d1\u89c6\u6587\u4ef6\u5185\u5bb9\u7684\u66f4\u6539\uff0c\u4f7f\u7528-f<\/code>\u9009\u9879\u3002\u8fd9\u4e2a\u9009\u9879\u5bf9\u4e8e\u76d1\u89c6\u65e5\u5fd7\u6587\u4ef6\u975e\u5e38\u6709\u7528\u3002\u4f8b\u5982\uff0c\u8981\u663e\u793a\/var\/log\/nginx\/error.log\u6587\u4ef6\u7684\u6700\u540e10\u884c\uff0c\u5e76\u76d1\u89c6\u6587\u4ef6\u7684\u66f4\u65b0\uff1a<\/p>\n

\r\n[root@localhost ~]# tail -f \/var\/log\/messages\r\n<\/pre>\n

\"\"
\n\u60f3\u8981\u9000\u51fa\uff0c\u8bf7\u6309Ctrl+C<\/code>\u9000\u51fa\u3002<\/p>\n

\u67e5\u770b\u591a\u4e2a\u6587\u4ef6<\/strong><\/div>\n

\u5982\u679c\u63d0\u4f9b\u4e86\u591a\u4e2a\u6587\u4ef6\u4f5c\u4e3atail\u547d\u4ee4\u7684\u8f93\u5165\uff0c\u5b83\u5c06\u663e\u793a\u6bcf\u4e2a\u6587\u4ef6\u7684\u6700\u540e\u5341\u884c\u3002\u4e0b\u9762\u4f8b\u5b50\uff0c\u4f7f\u7528tail<\/code>\u547d\u4ee4\u663e\u793a\/etc\/passwd<\/code>\u548c\/etc\/shadow<\/code>\u6587\u4ef6\u7684\u6700\u540e\u4e24\u884c\u5185\u5bb9\uff1a<\/p>\n

\r\n[root@localhost ~]# tail -n 2 \/etc\/passwd \/etc\/shadow\r\n==> \/etc\/passwd <==\r\nbob:x:1000:1001::\/home\/bob:\/bin\/bash\r\nuser01:x:1001:1002::\/home\/user01:\/bin\/bash\r\n\r\n==> \/etc\/shadow <==\r\nbob:!!:18333:0:99999:7:::\r\nuser01:$6$qPoy4v75$jzkBdrR.1L5G1sIs34GXRWa43fej.CLgaWKO9WRGkYcrUSVmVBGfcmOjn1Kc8FgcwVv2abac7t\/m3crt2Vu8G.:18335:0:99999:7:::\r\n<\/pre>\n

\"\"<\/p>\n

tail\u547d\u4ee4\u548c\u5176\u4ed6\u547d\u4ee4\u4e00\u8d77\u4f7f\u7528<\/strong><\/div>\n

\u4f8b\u5982\uff0c\u8981\u5b9e\u65f6\u76d1\u89c6apache\u8bbf\u95ee\u65e5\u5fd7\u6587\u4ef6\u5e76\u663e\u793a\u5305\u542bIP\u5730\u5740192.168.43.157\u7684\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n

\r\n[root@localhost ~]# tail -f \/var\/log\/httpd\/access_log |grep 192.168.43.157\r\n192.168.43.157 - - [28\/May\/2020:14:56:31 +0800] \"GET \/ HTTP\/1.1\" 403 4897 \"-\" \"curl\/7.29.0\"\r\n192.168.43.157 - - [28\/May\/2020:14:56:41 +0800] \"GET \/ HTTP\/1.1\" 403 4897 \"-\" \"curl\/7.29.0\"\r\n192.168.43.157 - - [28\/May\/2020:14:56:41 +0800] \"GET \/ HTTP\/1.1\" 403 4897 \"-\" \"curl\/7.29.0\"\r\n192.168.43.157 - - [28\/May\/2020:14:56:41 +0800] \"GET \/ HTTP\/1.1\" 403 4897 \"-\" \"curl\/7.29.0\"\r\n<\/pre>\n

\"\"<\/p>\n

\u603b\u7ed3<\/strong><\/div>\n

tail\u547d\u4ee4\u5c06\u6bcf\u4e2a\u6587\u4ef6\u7684\u6700\u540e10\u884c\u6253\u5370\u5230\u6807\u51c6\u8f93\u51fa\u3002\u5bf9\u4e8e\u591a\u4e2a\u6587\u4ef6\uff0c\u5728\u6bcf\u4e2a\u6587\u4ef6\u524d\u9762\u52a0\u4e0a\u4e00\u4e2a\u7ed9\u51fa\u6587\u4ef6\u540d\u7684\u5934\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4f7f\u7528tail\u547d\u4ee4\u67e5\u770byum.log\u65e5\u5fd7\u6587\u4ef6\uff0c\u663e\u793a\u6700\u540e10\u884c\u5185\u5bb9\uff0ctail\u9ed8\u8ba4\u663e\u793a\u95ee\u4ef7\u4f60\u7684\u6700\u540e10\u884c\u5185\u5bb9\uff1a [r […]<\/p>\n","protected":false},"author":362,"featured_media":193644,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-193643","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\/193643","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\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=193643"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/193643\/revisions"}],"predecessor-version":[{"id":193650,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/193643\/revisions\/193650"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/193644"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=193643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=193643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=193643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}