{"id":112116,"date":"2026-10-02T18:24:52","date_gmt":"2026-10-02T10:24:52","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/112116.html"},"modified":"2026-10-02T18:24:52","modified_gmt":"2026-10-02T10:24:52","slug":"day6-linux%e6%a0%87%e5%87%86io%e4%b8%8e%e6%97%a5%e5%bf%97%e6%96%87%e4%bb%b6%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/112116.html","title":{"rendered":"Day6 Linux\u6807\u51c6IO\u4e0e\u65e5\u5fd7\u6587\u4ef6\u5904\u7406"},"content":{"rendered":"<h2>Linux \u6807\u51c6 IO&#xff08;\u8f93\u5165\/\u8f93\u51fa&#xff09;\u4e0e\u65e5\u5fd7\u6587\u4ef6\u5904\u7406<\/h2>\n<p>\u7ee7\u4e0a\u4e00\u7bc7\u300a\u76ee\u5f55\u3001\u914d\u7f6e\u6587\u4ef6\u4e0e\u65e5\u5fd7\u6587\u4ef6\u7ba1\u7406\u300b&#xff08;pwd\u3001cp \u7b49\u547d\u4ee4&#xff09;\u4e4b\u540e&#xff0c;\u672c\u7bc7\u8bb2\u89e3 Linux \u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u4e2a\u57fa\u7840\u6982\u5ff5\u2014\u2014\u6807\u51c6 IO&#xff0c;\u4ee5\u53ca\u56f4\u7ed5\u5b83\u884d\u751f\u51fa\u7684\u91cd\u5b9a\u5411\u3001\u7ba1\u9053\u548c\u4e09\u5927\u6587\u672c\u5904\u7406\u5de5\u5177&#xff08;grep \/ sed \/ awk&#xff09;\u3002\u8fd9\u4e9b\u5185\u5bb9\u662f\u540e\u7eed\u505a\u65e5\u5fd7\u5206\u6790\u3001\u6545\u969c\u6392\u67e5\u548c Shell \u811a\u672c\u7f16\u5199\u7684\u5730\u57fa\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u6807\u51c6 IO&#xff1a;\u4e09\u79cd\u6570\u636e\u6d41<\/h3>\n<p>\u5728 Linux \u4e2d&#xff0c;\u4e00\u5207\u7686\u6587\u4ef6&#xff0c;\u7a0b\u5e8f\u7684\u8f93\u5165\u8f93\u51fa\u4e5f\u88ab\u62bd\u8c61\u4e3a&#034;\u6570\u636e\u6d41&#034;\u3002\u6bcf\u6267\u884c\u4e00\u4e2a\u547d\u4ee4&#xff0c;\u7cfb\u7edf\u90fd\u4f1a\u4e3a\u5176\u9ed8\u8ba4\u6253\u5f00\u4e09\u4e2a\u6570\u636e\u6d41&#xff0c;\u5e76\u7528**\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff08;File Descriptor, fd&#xff09;**\u8fdb\u884c\u7f16\u53f7&#xff1a;<\/p>\n<table>\n<tr>\u6587\u4ef6\u63cf\u8ff0\u7b26\u540d\u79f0\u82f1\u6587\u9ed8\u8ba4\u6307\u5411\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td align=\"center\">0<\/td>\n<td align=\"left\">\u6807\u51c6\u8f93\u5165<\/td>\n<td align=\"left\">stdin (Standard Input)<\/td>\n<td align=\"left\">\u952e\u76d8<\/td>\n<td align=\"left\">\u7a0b\u5e8f\u8bfb\u53d6\u6570\u636e\u7684\u6765\u6e90<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">1<\/td>\n<td align=\"left\">\u6807\u51c6\u8f93\u51fa<\/td>\n<td align=\"left\">stdout (Standard Output)<\/td>\n<td align=\"left\">\u7ec8\u7aef\u5c4f\u5e55<\/td>\n<td align=\"left\">\u7a0b\u5e8f\u6b63\u786e\u7ed3\u679c\u7684\u8f93\u51fa<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">2<\/td>\n<td align=\"left\">\u6807\u51c6\u9519\u8bef<\/td>\n<td align=\"left\">stderr (Standard Error)<\/td>\n<td align=\"left\">\u7ec8\u7aef\u5c4f\u5e55<\/td>\n<td align=\"left\">\u7a0b\u5e8f\u9519\u8bef\u4fe1\u606f\u7684\u8f93\u51fa<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261002102451-6abf8673433e3.png\" alt=\"\u8bf7\u6dfb\u52a0\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u6267\u884c\u547d\u4ee4\u65f6&#xff0c;\u6b63\u786e\u7ed3\u679c\u548c\u9519\u8bef\u7ed3\u679c\u9ed8\u8ba4\u90fd\u4f1a\u663e\u793a\u5728\u7ec8\u7aef\u4e2d&#xff0c;\u8fd9\u662f\u56e0\u4e3a stdout&#xff08;1&#xff09;\u548c stderr&#xff08;2&#xff09;\u7684\u9ed8\u8ba4\u76ee\u7684\u5730\u90fd\u662f\u7ec8\u7aef\u8bbe\u5907\u3002\u4f46\u5b83\u4eec\u672c\u8d28\u662f\u4e24\u6761\u76f8\u4e92\u72ec\u7acb\u7684\u6d41&#xff0c;\u53ef\u4ee5\u5206\u522b\u91cd\u5b9a\u5411\u5230\u4e0d\u540c\u7684\u5730\u65b9\u2014\u2014\u8fd9\u662f\u65e5\u5fd7\u5206\u79bb\u3001\u9519\u8bef\u6392\u67e5\u7684\u57fa\u7840\u3002<\/p>\n<p>\u9a8c\u8bc1\u793a\u4f8b&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u540c\u65f6\u4ea7\u751f\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef<\/span><br \/>\n<span class=\"token function\">ls<\/span> \/etc\/passwd \/notexist<\/p>\n<p>\u8f93\u51fa\u4e2d ls: cannot access &#039;\/notexist&#039;: No such file or directory \u8d70\u7684\u662f stderr&#xff08;fd 2&#xff09;&#xff0c;\u800c \/etc\/passwd \u8d70\u7684\u662f stdout&#xff08;fd 1&#xff09;\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u8f93\u51fa\u91cd\u5b9a\u5411&#xff1a;&gt;\u3001&gt;&gt;\u30012&gt;<\/h3>\n<p>\u91cd\u5b9a\u5411\u7684\u672c\u8d28&#xff1a;\u6539\u53d8\u6570\u636e\u6d41\u7684\u9ed8\u8ba4\u76ee\u7684\u5730&#xff0c;\u628a\u539f\u672c\u8f93\u51fa\u5230\u5c4f\u5e55\u7684\u5185\u5bb9\u8f6c\u5b58\u5230\u6587\u4ef6\u4e2d\u3002<\/p>\n<h4>1. &gt;&#xff1a;\u8986\u76d6\u5f0f\u91cd\u5b9a\u5411\u6807\u51c6\u8f93\u51fa<\/h4>\n<p>\u5c06\u547d\u4ee4\u7684\u6b63\u786e\u7ed3\u679c\u5199\u5165\u6587\u4ef6&#xff0c;\u6587\u4ef6\u539f\u6709\u5185\u5bb9\u4f1a\u88ab\u6e05\u7a7a\u8986\u76d6\u3002\u6587\u4ef6\u4e0d\u5b58\u5728\u5219\u81ea\u52a8\u521b\u5efa\u3002<\/p>\n<p><span class=\"token comment\"># \u628a\u76ee\u5f55\u6e05\u5355\u4fdd\u5b58\u5230\u6587\u4ef6<\/span><br \/>\n<span class=\"token function\">ls<\/span> <span class=\"token parameter variable\">-l<\/span> \/etc <span class=\"token operator\">&gt;<\/span> etc_list.txt<\/p>\n<p><span class=\"token comment\"># \u6e05\u7a7a\u4e00\u4e2a\u6587\u4ef6&#xff08;\u5229\u7528\u7a7a\u8f93\u51fa\u7684\u8986\u76d6\u7279\u6027&#xff09;<\/span><br \/>\n<span class=\"token operator\">&gt;<\/span> app.log<\/p>\n<p>\u26a0\ufe0f &gt; \u662f\u8986\u76d6\u5199&#xff0c;\u751f\u4ea7\u73af\u5883\u5bf9\u91cd\u8981\u6587\u4ef6\u64cd\u4f5c\u524d\u52a1\u5fc5\u786e\u8ba4&#xff0c;\u907f\u514d\u8bef\u6e05\u6570\u636e\u3002<\/p>\n<h4>2. &gt;&gt;&#xff1a;\u8ffd\u52a0\u5f0f\u91cd\u5b9a\u5411\u6807\u51c6\u8f93\u51fa<\/h4>\n<p>\u4e0e &gt; \u7684\u552f\u4e00\u533a\u522b&#xff1a;\u4e0d\u6e05\u7a7a\u539f\u5185\u5bb9&#xff0c;\u5728\u6587\u4ef6\u672b\u5c3e\u8ffd\u52a0\u3002\u65e5\u5fd7\u8bb0\u5f55\u573a\u666f\u51e0\u4e4e\u90fd\u7528 &gt;&gt;\u3002<\/p>\n<p><span class=\"token comment\"># \u6301\u7eed\u8bb0\u5f55\u7cfb\u7edf\u8d1f\u8f7d&#xff0c;\u4e0d\u8986\u76d6\u5386\u53f2\u6570\u636e<\/span><br \/>\n<span class=\"token function\">uptime<\/span> <span class=\"token operator\">&gt;&gt;<\/span> \/var\/log\/load_monitor.log<\/p>\n<p><span class=\"token comment\"># \u591a\u6b21\u6267\u884c&#xff0c;\u5185\u5bb9\u9010\u884c\u7d2f\u79ef<\/span><br \/>\n<span class=\"token function\">date<\/span> <span class=\"token operator\">&gt;&gt;<\/span> run.log<br \/>\n<span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;\u4efb\u52a1\u6267\u884c\u5b8c\u6210&#034;<\/span> <span class=\"token operator\">&gt;&gt;<\/span> run.log<\/p>\n<h4>3. 2&gt; \/ 2&gt;&gt;&#xff1a;\u91cd\u5b9a\u5411\u6807\u51c6\u9519\u8bef<\/h4>\n<p>\u7b26\u53f7\u524d\u7684\u6570\u5b57\u5c31\u662f\u6587\u4ef6\u63cf\u8ff0\u7b26\u30022&gt; \u53ea\u6355\u83b7\u9519\u8bef\u8f93\u51fa&#xff0c;\u6b63\u786e\u7ed3\u679c\u4ecd\u663e\u793a\u5728\u5c4f\u5e55\u3002<\/p>\n<p><span class=\"token comment\"># \u628a\u62a5\u9519\u4fe1\u606f\u5355\u72ec\u5b58\u5230\u9519\u8bef\u65e5\u5fd7<\/span><br \/>\n<span class=\"token function\">ls<\/span> \/notexist <span class=\"token operator\"><span class=\"token file-descriptor important\">2<\/span>&gt;<\/span> error.log<\/p>\n<p><span class=\"token comment\"># find \u904d\u5386\u5168\u76d8\u65f6\u6743\u9650\u4e0d\u8db3\u7684\u62a5\u9519\u5f88\u591a&#xff0c;\u4e22\u5f03\u5230&#034;\u9ed1\u6d1e&#034;<\/span><br \/>\n<span class=\"token function\">find<\/span> \/ <span class=\"token parameter variable\">-name<\/span> <span class=\"token string\">&#034;nginx.conf&#034;<\/span> <span class=\"token operator\"><span class=\"token file-descriptor important\">2<\/span>&gt;<\/span> \/dev\/null<\/p>\n<p>\/dev\/null \u662f Linux \u7684&#034;\u9ed1\u6d1e\u8bbe\u5907&#034;&#xff0c;\u5199\u5165\u5b83\u7684\u4efb\u4f55\u6570\u636e\u90fd\u4f1a\u88ab\u76f4\u63a5\u4e22\u5f03&#xff0c;\u5e38\u7528\u4e8e\u5c4f\u853d\u65e0\u7528\u8f93\u51fa\u3002<\/p>\n<h4><\/h4>\n<p>\u91cd\u70b9\u7406\u89e3 2&gt;&amp;1&#xff1a;\u5b83\u7684\u542b\u4e49\u662f&#034;\u8ba9 fd 2 \u6307\u5411 fd 1 \u5f53\u524d\u6307\u5411\u7684\u5730\u65b9&#034;\u3002\u4e0b\u9762\u4e24\u6761\u547d\u4ee4\u987a\u5e8f\u4e0d\u540c&#xff0c;\u7ed3\u679c\u5b8c\u5168\u4e0d\u540c&#xff1a;<\/p>\n<p>.\/app.sh <span class=\"token operator\">&gt;<\/span> all.log <span class=\"token operator\"><span class=\"token file-descriptor important\">2<\/span>&gt;<\/span><span class=\"token file-descriptor important\">&amp;1<\/span>   <span class=\"token comment\"># \u2705 \u6b63\u786e&#xff1a;stdout \u5148\u8fdb\u6587\u4ef6&#xff0c;stderr \u518d\u8ddf\u968f\u8fdb\u6587\u4ef6<\/span><br \/>\n.\/app.sh <span class=\"token operator\"><span class=\"token file-descriptor important\">2<\/span>&gt;<\/span><span class=\"token file-descriptor important\">&amp;1<\/span> <span class=\"token operator\">&gt;<\/span> all.log   <span class=\"token comment\"># \u274c \u9519\u8bef&#xff1a;stderr \u5148\u8ddf\u968f stdout&#xff08;\u6b64\u65f6\u8fd8\u662f\u5c4f\u5e55&#xff09;&#xff0c;\u4e4b\u540e stdout \u624d\u8fdb\u6587\u4ef6<\/span><\/p>\n<hr \/>\n<h3>\u4e09\u3001\u8f93\u5165\u91cd\u5b9a\u5411&#xff1a;&lt;<\/h3>\n<p>&gt; A\u6539\u53d8\u7684\u662f\u8f93\u51fa\u7684\u53bb\u5411&#xff0c;&lt; \u5219\u76f8\u53cd&#xff1a;\u8ba9\u547d\u4ee4\u4e0d\u518d\u4ece\u952e\u76d8\u8bfb\u53d6\u8f93\u5165&#xff0c;\u6539\u4e3a\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u3002<\/p>\n<p><span class=\"token comment\"># \u7edf\u8ba1\u6587\u4ef6\u884c\u6570&#xff08;\u6ce8\u610f&#xff1a;wc -l file \u4e0e wc -l &lt; file \u8f93\u51fa\u683c\u5f0f\u7565\u6709\u5dee\u5f02&#xff09;<\/span><br \/>\n<span class=\"token function\">wc<\/span> <span class=\"token parameter variable\">-l<\/span> <span class=\"token operator\">&lt;<\/span> \/etc\/passwd<\/p>\n<p><span class=\"token comment\"># \u628a\u6587\u4ef6\u5185\u5bb9\u4f5c\u4e3a\u90ae\u4ef6\u6b63\u6587\u53d1\u9001<\/span><br \/>\nmail <span class=\"token parameter variable\">-s<\/span> <span class=\"token string\">&#034;\u65e5\u62a5&#034;<\/span> admin&#064;example.com <span class=\"token operator\">&lt;<\/span> report.txt<\/p>\n<p><span class=\"token comment\"># \u6279\u91cf\u521b\u5efa\u7528\u6237\u65f6&#xff0c;\u4ece\u6587\u4ef6\u8bfb\u5165\u7528\u6237\u5217\u8868<\/span><br \/>\n<span class=\"token keyword\">while<\/span> <span class=\"token builtin class-name\">read<\/span> user<span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">do<\/span> <span class=\"token function\">useradd<\/span> <span class=\"token string\">&#034;<span class=\"token variable\">$user<\/span>&#034;<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">done<\/span> <span class=\"token operator\">&lt;<\/span> users.txt<\/p>\n<p>\u8865\u5145&#xff1a;&lt;&lt;&#xff08;Here Document&#xff0c;\u6b64\u5904\u6587\u6863&#xff09;&#xff0c;\u5728\u811a\u672c\u4e2d\u5185\u8054\u63d0\u4f9b\u591a\u884c\u8f93\u5165&#xff1a;<\/p>\n<p><span class=\"token function\">cat<\/span> <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">EOF<span class=\"token bash punctuation\"> <span class=\"token operator\">&gt;<\/span> \/etc\/motd<\/span><br \/>\n&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n  \u670d\u52a1\u5668\u5df2\u52a0\u56fa&#xff0c;\u8bf7\u52ff\u8fdd\u89c4\u64cd\u4f5c<br \/>\n&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nEOF<\/span><\/p>\n<hr \/>\n<h3>\u56db\u3001\u7ba1\u9053 | \u4e0e tee<\/h3>\n<h4>1. \u7ba1\u9053 |&#xff1a;\u547d\u4ee4\u4e4b\u95f4\u7684&#034;\u4f20\u9001\u5e26&#034;<\/h4>\n<p>\u7ba1\u9053\u5c06\u524d\u4e00\u4e2a\u547d\u4ee4\u7684\u6807\u51c6\u8f93\u51fa\u4f5c\u4e3a\u540e\u4e00\u4e2a\u547d\u4ee4\u7684\u6807\u51c6\u8f93\u5165&#xff0c;\u5b9e\u73b0\u591a\u4e2a\u547d\u4ee4\u7684\u4e32\u8054\u534f\u4f5c\u3002\u6ce8\u610f&#xff1a;\u7ba1\u9053\u53ea\u4f20\u9012 stdout&#xff08;fd 1&#xff09;&#xff0c;stderr \u4e0d\u4f1a\u88ab\u4f20\u9012\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261002102451-6abf8673616a7.png\" alt=\"\u8bf7\u6dfb\u52a0\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><span class=\"token comment\"># \u67e5\u770b\u76d1\u542c\u4e2d\u7684 TCP \u7aef\u53e3<\/span><br \/>\nss <span class=\"token parameter variable\">-tlnp<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> LISTEN<\/p>\n<p><span class=\"token comment\"># \u7edf\u8ba1\u5f53\u524d\u7cfb\u7edf\u6709\u591a\u5c11\u4e2a bash \u767b\u5f55\u4f1a\u8bdd<\/span><br \/>\n<span class=\"token function\">who<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">wc<\/span> <span class=\"token parameter variable\">-l<\/span><\/p>\n<p><span class=\"token comment\"># \u591a\u7ea7\u7ba1\u9053&#xff1a;\u627e\u51fa\u5360\u7528\u5185\u5b58\u6700\u9ad8\u7684\u524d 5 \u4e2a\u8fdb\u7a0b<\/span><br \/>\n<span class=\"token function\">ps<\/span> aux <span class=\"token parameter variable\">&#8211;sort<\/span><span class=\"token operator\">&#061;<\/span>-%mem <span class=\"token operator\">|<\/span> <span class=\"token function\">head<\/span> <span class=\"token parameter variable\">-6<\/span><\/p>\n<p>\u5982\u9700\u8ba9\u9519\u8bef\u8f93\u51fa\u4e5f\u8fdb\u5165\u7ba1\u9053&#xff0c;\u5148\u5408\u5e76\u6570\u636e\u6d41&#xff1a;<\/p>\n<p>.\/app.sh <span class=\"token operator\"><span class=\"token file-descriptor important\">2<\/span>&gt;<\/span><span class=\"token file-descriptor important\">&amp;1<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> <span class=\"token string\">&#034;ERROR&#034;<\/span><\/p>\n<h4>2. tee&#xff1a;\u4e00\u4efd\u6570\u636e&#xff0c;\u4e24\u5904\u53bb\u5411<\/h4>\n<p>tee \u547d\u4ee4\u8bfb\u53d6\u6807\u51c6\u8f93\u5165&#xff0c;\u540c\u65f6\u8f93\u51fa\u5230\u5c4f\u5e55\u548c\u6587\u4ef6\u2014\u2014\u5c31\u50cf\u6c34\u7ba1\u4e0a\u7684\u4e09\u901a\u63a5\u5934\u3002\u9700\u8981&#034;\u65e2\u770b\u5b9e\u65f6\u8f93\u51fa\u3001\u53c8\u7559\u6863\u8bb0\u5f55&#034;\u65f6\u975e\u5e38\u5b9e\u7528\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261002102451-6abf867370bcb.png\" alt=\"\u8bf7\u6dfb\u52a0\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><span class=\"token comment\"># \u5b89\u88c5\u8fc7\u7a0b\u65e2\u5728\u5c4f\u5e55\u663e\u793a&#xff0c;\u53c8\u4fdd\u5b58\u5230\u65e5\u5fd7<\/span><br \/>\nyum <span class=\"token function\">install<\/span> nginx <span class=\"token parameter variable\">-y<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">tee<\/span> install.log<\/p>\n<p><span class=\"token comment\"># -a \u9009\u9879&#xff1a;\u8ffd\u52a0\u800c\u975e\u8986\u76d6<\/span><br \/>\n.\/deploy.sh <span class=\"token operator\">|<\/span> <span class=\"token function\">tee<\/span> <span class=\"token parameter variable\">-a<\/span> deploy_history.log<\/p>\n<p><span class=\"token comment\"># \u914d\u5408 sudo \u5199\u5165\u65e0\u6743\u9650\u7684\u6587\u4ef6&#xff08;\u7ecf\u5178\u7528\u6cd5&#xff1a;echo \u672c\u8eab\u6ca1\u6709\u6743\u9650&#xff0c;\u9760 tee \u63d0\u6743\u5199\u5165&#xff09;<\/span><br \/>\n<span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;net.ipv4.ip_forward &#061; 1&#034;<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">sudo<\/span> <span class=\"token function\">tee<\/span> <span class=\"token parameter variable\">-a<\/span> \/etc\/sysctl.conf<\/p>\n<hr \/>\n<h3>\u4e94\u3001grep \u4e0e\u6b63\u5219\u8868\u8fbe\u5f0f&#xff1a;\u65e5\u5fd7\u68c0\u7d22\u7684\u5229\u5668<\/h3>\n<p>grep&#xff08;Global Regular Expression Print&#xff09;\u6309\u6a21\u5f0f\u9010\u884c\u8fc7\u6ee4\u6587\u672c&#xff0c;\u662f\u65e5\u5fd7\u5206\u6790\u4e2d\u4f7f\u7528\u9891\u7387\u6700\u9ad8\u7684\u547d\u4ee4\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261002102451-6abf867381208.png\" alt=\"\u8bf7\u6dfb\u52a0\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>1. \u5e38\u7528\u9009\u9879<\/h4>\n<table>\n<tr>\u9009\u9879\u4f5c\u7528\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">-i<\/td>\n<td align=\"left\">\u5ffd\u7565\u5927\u5c0f\u5199<\/td>\n<td align=\"left\">grep -i &#034;error&#034; app.log<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">-v<\/td>\n<td align=\"left\">\u53cd\u5411\u5339\u914d&#xff08;\u663e\u793a\u4e0d\u542b\u5173\u952e\u5b57\u7684\u884c&#xff09;<\/td>\n<td align=\"left\">grep -v &#034;^#&#034; nginx.conf<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">-n<\/td>\n<td align=\"left\">\u663e\u793a\u5339\u914d\u884c\u7684\u884c\u53f7<\/td>\n<td align=\"left\">grep -n &#034;failed&#034; secure.log<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">-c<\/td>\n<td align=\"left\">\u53ea\u7edf\u8ba1\u5339\u914d\u7684\u884c\u6570<\/td>\n<td align=\"left\">grep -c &#034;404&#034; access.log<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">-r<\/td>\n<td align=\"left\">\u9012\u5f52\u641c\u7d22\u76ee\u5f55<\/td>\n<td align=\"left\">grep -r &#034;password&#034; \/etc\/<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">-w<\/td>\n<td align=\"left\">\u6574\u8bcd\u5339\u914d<\/td>\n<td align=\"left\">grep -w &#034;root&#034; \/etc\/passwd<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">-A n<\/td>\n<td align=\"left\">\u663e\u793a\u5339\u914d\u884c\u53ca\u5176\u540e n \u884c (After)<\/td>\n<td align=\"left\">grep -A 3 &#034;ERROR&#034; app.log<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">-B n<\/td>\n<td align=\"left\">\u663e\u793a\u5339\u914d\u884c\u53ca\u5176\u524d n \u884c (Before)<\/td>\n<td align=\"left\">grep -B 3 &#034;ERROR&#034; app.log<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">-E<\/td>\n<td align=\"left\">\u542f\u7528\u6269\u5c55\u6b63\u5219&#xff08;\u7b49\u4ef7\u4e8e egrep&#xff09;<\/td>\n<td align=\"left\">&#096;grep -E &#034;404<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2. \u57fa\u7840\u6b63\u5219\u8868\u8fbe\u5f0f&#xff08;BRE&#xff09;\u5e38\u7528\u5143\u5b57\u7b26<\/h4>\n<table>\n<tr>\u7b26\u53f7\u542b\u4e49\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">^<\/td>\n<td align=\"left\">\u884c\u9996\u951a\u5b9a<\/td>\n<td align=\"left\">grep &#034;^root&#034; \/etc\/passwd \u5339\u914d\u4ee5 root \u5f00\u5934\u7684\u884c<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">$<\/td>\n<td align=\"left\">\u884c\u5c3e\u951a\u5b9a<\/td>\n<td align=\"left\">grep &#034;bash$&#034; \/etc\/passwd \u5339\u914d\u4ee5 bash \u7ed3\u5c3e\u7684\u884c<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">.<\/td>\n<td align=\"left\">\u5339\u914d\u4efb\u610f\u5355\u4e2a\u5b57\u7b26<\/td>\n<td align=\"left\">grep &#034;r..t&#034; file \u53ef\u5339\u914d root\u3001rust<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">*<\/td>\n<td align=\"left\">\u524d\u4e00\u4e2a\u5b57\u7b26\u51fa\u73b0 0 \u6b21\u6216\u591a\u6b21<\/td>\n<td align=\"left\">grep &#034;ab*c&#034; file<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">[&#8230;]<\/td>\n<td align=\"left\">\u5b57\u7b26\u96c6\u5408<\/td>\n<td align=\"left\">grep &#034;[0-9]&#034; file \u5339\u914d\u542b\u6570\u5b57\u7684\u884c<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">[^&#8230;]<\/td>\n<td align=\"left\">\u5b57\u7b26\u96c6\u5408\u53d6\u53cd<\/td>\n<td align=\"left\">grep -v &#034;^#&#034; nginx.conf | grep -v &#034;^$&#034; \u8fc7\u6ee4\u6ce8\u91ca\u548c\u7a7a\u884c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5b9e\u6218\u793a\u4f8b\u2014\u2014\u5206\u6790 Nginx \u8bbf\u95ee\u65e5\u5fd7&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u627e\u51fa\u6240\u6709 5xx \u670d\u52a1\u7aef\u9519\u8bef<\/span><br \/>\n<span class=\"token function\">grep<\/span> <span class=\"token parameter variable\">-E<\/span> <span class=\"token string\">&#039;&#034; 5[0-9]{2} &#039;<\/span> \/var\/log\/nginx\/access.log<\/p>\n<p><span class=\"token comment\"># \u7edf\u8ba1\u4eca\u5929 404 \u51fa\u73b0\u7684\u6b21\u6570<\/span><br \/>\n<span class=\"token function\">grep<\/span> <span class=\"token parameter variable\">-c<\/span> <span class=\"token string\">&#034;404&#034;<\/span> \/var\/log\/nginx\/access.log<\/p>\n<p><span class=\"token comment\"># \u67e5\u770b\u67d0\u4e2a IP \u7684\u5168\u90e8\u8bbf\u95ee\u8bb0\u5f55<\/span><br \/>\n<span class=\"token function\">grep<\/span> <span class=\"token string\">&#034;192.168.10.100&#034;<\/span> \/var\/log\/nginx\/access.log<\/p>\n<hr \/>\n<h3>\u516d\u3001sed&#xff1a;\u6d41\u5f0f\u6587\u672c\u7f16\u8f91\u5668<\/h3>\n<p>sed&#xff08;Stream Editor&#xff09;\u9010\u884c\u8bfb\u53d6\u6587\u672c&#xff0c;\u6309\u89c4\u5219\u8fdb\u884c\u589e\u3001\u5220\u3001\u6539\u3001\u67e5&#xff0c;\u9002\u5408\u6279\u91cf\u3001\u975e\u4ea4\u4e92\u5f0f\u7684\u6587\u672c\u4fee\u6539\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261002102451-6abf867393315.png\" alt=\"\u8bf7\u6dfb\u52a0\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>1. \u6838\u5fc3\u8bed\u6cd5<\/h4>\n<p>sed [\u9009\u9879] &#039;\u52a8\u4f5c&#039; \u6587\u4ef6<\/p>\n<h4>2. \u66ff\u6362&#xff08;\u6700\u5e38\u7528&#xff09;<\/h4>\n<p><span class=\"token comment\"># \u683c\u5f0f&#xff1a;s\/\u65e7\u5185\u5bb9\/\u65b0\u5185\u5bb9\/\u6807\u5fd7<\/span><br \/>\n<span class=\"token comment\"># \u53ea\u66ff\u6362\u6bcf\u884c\u7b2c\u4e00\u4e2a\u5339\u914d\u9879&#xff08;\u9ed8\u8ba4&#xff09;<\/span><br \/>\n<span class=\"token function\">sed<\/span> <span class=\"token string\">&#039;s\/error\/ERROR\/&#039;<\/span> app.log<\/p>\n<p><span class=\"token comment\"># g \u6807\u5fd7&#xff1a;\u66ff\u6362\u6bcf\u884c\u6240\u6709\u5339\u914d\u9879<\/span><br \/>\n<span class=\"token function\">sed<\/span> <span class=\"token string\">&#039;s\/8080\/9090\/g&#039;<\/span> nginx.conf<\/p>\n<p><span class=\"token comment\"># -i&#xff1a;\u76f4\u63a5\u4fee\u6539\u6587\u4ef6\u5185\u5bb9&#xff08;\u4e0d\u5e26 -i \u65f6\u53ea\u5728\u5c4f\u5e55\u9884\u89c8&#xff0c;\u4e0d\u6539\u539f\u6587\u4ef6&#xff0c;\u5efa\u8bae\u5148\u9884\u89c8\u518d\u52a0 -i&#xff09;<\/span><br \/>\n<span class=\"token function\">sed<\/span> <span class=\"token parameter variable\">-i<\/span> <span class=\"token string\">&#039;s\/SELINUX&#061;enforcing\/SELINUX&#061;disabled\/&#039;<\/span> \/etc\/selinux\/config<\/p>\n<p><span class=\"token comment\"># \u4fee\u6539\u524d\u81ea\u52a8\u5907\u4efd\u539f\u6587\u4ef6\u4e3a .bak<\/span><br \/>\n<span class=\"token function\">sed<\/span> <span class=\"token parameter variable\">-i.bak<\/span> <span class=\"token string\">&#039;s\/8080\/9090\/g&#039;<\/span> nginx.conf<\/p>\n<h4>3. \u5220\u9664\u4e0e\u6309\u884c\u64cd\u4f5c<\/h4>\n<p><span class=\"token comment\"># \u5220\u9664\u7b2c 5 \u884c<\/span><br \/>\n<span class=\"token function\">sed<\/span> <span class=\"token string\">&#039;5d&#039;<\/span> <span class=\"token function\">file<\/span><\/p>\n<p><span class=\"token comment\"># \u5220\u9664\u6240\u6709\u7a7a\u884c<\/span><br \/>\n<span class=\"token function\">sed<\/span> <span class=\"token string\">&#039;\/^$\/d&#039;<\/span> <span class=\"token function\">file<\/span><\/p>\n<p><span class=\"token comment\"># \u5220\u9664\u6240\u6709\u6ce8\u91ca\u884c<\/span><br \/>\n<span class=\"token function\">sed<\/span> <span class=\"token string\">&#039;\/^#\/d&#039;<\/span> nginx.conf<\/p>\n<p><span class=\"token comment\"># \u53ea\u6253\u5370\u7b2c 10~20 \u884c&#xff08;\u914d\u5408 -n \u6291\u5236\u9ed8\u8ba4\u8f93\u51fa&#xff09;<\/span><br \/>\n<span class=\"token function\">sed<\/span> <span class=\"token parameter variable\">-n<\/span> <span class=\"token string\">&#039;10,20p&#039;<\/span> app.log<\/p>\n<h4>4. \u5b9e\u6218\u793a\u4f8b<\/h4>\n<p><span class=\"token comment\"># \u5feb\u901f\u67e5\u770b\u914d\u7f6e\u6587\u4ef6\u6709\u6548\u5185\u5bb9&#xff08;\u53bb\u6389\u6ce8\u91ca\u548c\u7a7a\u884c&#xff09;<\/span><br \/>\n<span class=\"token function\">grep<\/span> <span class=\"token parameter variable\">-v<\/span> <span class=\"token string\">&#034;^#&#034;<\/span> nginx.conf <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> <span class=\"token parameter variable\">-v<\/span> <span class=\"token string\">&#034;^$&#034;<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">sed<\/span> <span class=\"token string\">&#039;s\/^[ \\\\t]*\/\/&#039;<\/span><\/p>\n<p><span class=\"token comment\"># \u6279\u91cf\u628a\u65e5\u5fd7\u4e2d\u7684\u624b\u673a\u53f7\u8131\u654f&#xff08;\u6269\u5c55\u6b63\u5219\u7528 -r \u6216 -E&#xff09;<\/span><br \/>\n<span class=\"token function\">sed<\/span> <span class=\"token parameter variable\">-r<\/span> <span class=\"token string\">&#039;s\/(1[0-9]{2})[0-9]{4}([0-9]{4})\/\\\\1****\\\\2\/g&#039;<\/span> user.log<\/p>\n<hr \/>\n<h3>\u4e03\u3001awk&#xff1a;\u5b57\u6bb5\u7ea7\u6587\u672c\u5904\u7406\u4e0e\u7edf\u8ba1<\/h3>\n<p>awk \u628a\u6bcf\u884c\u6587\u672c\u6309\u5206\u9694\u7b26\u5207\u5206\u6210\u5b57\u6bb5&#xff08;\u5217&#xff09;&#xff0c;\u53ef\u7cbe\u786e\u53d6\u5217\u3001\u8ba1\u7b97\u3001\u6c47\u603b&#xff0c;\u662f\u5904\u7406\u65e5\u5fd7\u548c\u62a5\u8868\u7684&#034;\u745e\u58eb\u519b\u5200&#034;\u3002<\/p>\n<p>![\u8bf7\u6dfb\u52a0\u56fe\u7247\u63cf\u8ff0](https:\/\/i-blog.csdnimg.cn\/direct\/5f071630c22d484d8883ab73c142643b.png<\/p>\n<h4>1. \u57fa\u672c\u6982\u5ff5<\/h4>\n<p>awk [\u9009\u9879] &#039;\u6a21\u5f0f {\u52a8\u4f5c}&#039; \u6587\u4ef6<\/p>\n<ul>\n<li>\u9ed8\u8ba4\u4ee5**\u7a7a\u767d\u5b57\u7b26&#xff08;\u7a7a\u683c\/Tab&#xff09;**\u4e3a\u5206\u9694\u7b26&#xff0c;-F \u53ef\u81ea\u5b9a\u4e49<\/li>\n<li>$0 \u8868\u793a\u6574\u884c&#xff0c;$1\u3001$2\u2026 \u8868\u793a\u7b2c 1\u30012\u2026 \u5217&#xff0c;$NF \u8868\u793a\u6700\u540e\u4e00\u5217<\/li>\n<li>NR \u5f53\u524d\u884c\u53f7&#xff0c;NF \u5f53\u524d\u884c\u7684\u5b57\u6bb5\u6570<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261002102451-6abf8673a1f75.png\" alt=\"\u8bf7\u6dfb\u52a0\u56fe\u7247\u63cf\u8ff0\" \/><\/li>\n<\/ul>\n<h4>2. \u53d6\u5217&#xff08;\u6700\u5e38\u7528&#xff09;<\/h4>\n<p><span class=\"token comment\"># \u6253\u5370\u7b2c 1 \u5217&#xff1a;\u67e5\u770b\u6240\u6709\u7528\u6237\u540d<\/span><br \/>\n<span class=\"token function\">awk<\/span> -F: <span class=\"token string\">&#039;{print $1}&#039;<\/span> \/etc\/passwd<\/p>\n<p><span class=\"token comment\"># \u6253\u5370\u7b2c 1 \u5217\u548c\u7b2c 3 \u5217&#xff0c;\u81ea\u5b9a\u4e49\u8f93\u51fa\u683c\u5f0f<\/span><br \/>\n<span class=\"token function\">awk<\/span> -F: <span class=\"token string\">&#039;{print &#034;\u7528\u6237:&#034; $1, &#034;UID:&#034; $3}&#039;<\/span> \/etc\/passwd<\/p>\n<p><span class=\"token comment\"># \u627e\u51fa UID \u5927\u4e8e\u7b49\u4e8e 1000 \u7684\u666e\u901a\u7528\u6237&#xff08;\u6761\u4ef6\u8fc7\u6ee4&#xff09;<\/span><br \/>\n<span class=\"token function\">awk<\/span> -F: <span class=\"token string\">&#039;$3 &gt;&#061; 1000 {print $1}&#039;<\/span> \/etc\/passwd<\/p>\n<h4>3. \u7edf\u8ba1\u5206\u6790&#xff08;\u65e5\u5fd7\u573a\u666f&#xff09;<\/h4>\n<p><span class=\"token comment\"># \u7edf\u8ba1 access.log \u4e2d\u5404 HTTP \u72b6\u6001\u7801\u51fa\u73b0\u7684\u6b21\u6570<\/span><br \/>\n<span class=\"token function\">awk<\/span> <span class=\"token string\">&#039;{print $9}&#039;<\/span> access.log <span class=\"token operator\">|<\/span> <span class=\"token function\">sort<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">uniq<\/span> <span class=\"token parameter variable\">-c<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">sort<\/span> <span class=\"token parameter variable\">-rn<\/span><\/p>\n<p><span class=\"token comment\"># \u7edf\u8ba1\u8bbf\u95ee\u91cf\u6700\u9ad8\u7684\u524d 10 \u4e2a IP&#xff08;awk \u5185\u5efa\u6570\u7ec4\u76f4\u63a5\u5b8c\u6210&#xff09;<\/span><br \/>\n<span class=\"token function\">awk<\/span> <span class=\"token string\">&#039;{count[$1]&#043;&#043;} END {for (ip in count) print count[ip], ip}&#039;<\/span> access.log <span class=\"token operator\">|<\/span> <span class=\"token function\">sort<\/span> <span class=\"token parameter variable\">-rn<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">head<\/span> <span class=\"token parameter variable\">-10<\/span><\/p>\n<p><span class=\"token comment\"># \u8ba1\u7b97\u67d0\u5217\u603b\u548c&#xff1a;\u7edf\u8ba1\u78c1\u76d8\u5404\u5206\u533a\u4f7f\u7528\u91cf\u4e4b\u548c<\/span><br \/>\n<span class=\"token function\">df<\/span> <span class=\"token parameter variable\">-m<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">awk<\/span> <span class=\"token string\">&#039;NR&gt;1 {sum &#043;&#061; $3} END {print &#034;\u603b\u4f7f\u7528: &#034; sum &#034; MB&#034;}&#039;<\/span><\/p>\n<p><span class=\"token comment\"># \u627e\u51fa\u54cd\u5e94\u5927\u5c0f\u8d85\u8fc7 1MB \u7684\u8bf7\u6c42<\/span><br \/>\n<span class=\"token function\">awk<\/span> <span class=\"token string\">&#039;$10 &gt; 1048576 {print $7, $10}&#039;<\/span> access.log<\/p>\n<h4>4. BEGIN \/ END \u5757<\/h4>\n<p><span class=\"token comment\"># BEGIN \u5728\u5904\u7406\u524d\u6267\u884c\u4e00\u6b21&#xff0c;END \u5728\u5904\u7406\u5b8c\u6267\u884c\u4e00\u6b21 \u2014\u2014 \u9002\u5408\u505a\u8868\u5934\u548c\u6c47\u603b<\/span><br \/>\n<span class=\"token function\">awk<\/span> -F: <span class=\"token string\">&#039;BEGIN {print &#034;&#061;&#061;&#061;&#061;&#061; \u7528\u6237\u5217\u8868 &#061;&#061;&#061;&#061;&#061;&#034;} {print NR&#034;. &#034;$1} END {print &#034;\u5171 &#034; NR &#034; \u4e2a\u7528\u6237&#034;}&#039;<\/span> \/etc\/passwd<\/p>\n<hr \/>\n<h3>\u516b\u3001\u7ec4\u5408\u5b9e\u6218&#xff1a;\u4e00\u6b21\u5b8c\u6574\u7684\u65e5\u5fd7\u6392\u67e5<\/h3>\n<p>\u5047\u8bbe\u7ebf\u4e0a\u63a5\u53e3\u62a5\u9519&#xff0c;\u9700\u8981\u6392\u67e5 Nginx \u65e5\u5fd7&#xff0c;\u5178\u578b\u6392\u67e5\u94fe\u8def\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token comment\"># 1. \u5148\u770b\u9519\u8bef\u65e5\u5fd7\u6700\u8fd1\u7684 50 \u6761\u8bb0\u5f55<\/span><br \/>\n<span class=\"token function\">tail<\/span> <span class=\"token parameter variable\">-50<\/span> \/var\/log\/nginx\/error.log<\/p>\n<p><span class=\"token comment\"># 2. \u5b9e\u65f6\u8ddf\u8e2a\u65e5\u5fd7&#xff08;\u6392\u969c\u5fc5\u5907&#xff0c;Ctrl&#043;C \u9000\u51fa&#xff09;<\/span><br \/>\n<span class=\"token function\">tail<\/span> <span class=\"token parameter variable\">-f<\/span> \/var\/log\/nginx\/access.log<\/p>\n<p><span class=\"token comment\"># 3. \u5b9a\u4f4d\u4eca\u5929 15 \u70b9\u5de6\u53f3\u7684\u6240\u6709 500 \u9519\u8bef&#xff0c;\u5e76\u4fdd\u5b58\u5230\u6587\u4ef6\u5907\u67e5<\/span><br \/>\n<span class=\"token function\">grep<\/span> <span class=\"token string\">&#034;30\/Sep\/2026:15&#034;<\/span> access.log <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> <span class=\"token string\">&#039;&#034; 500 &#039;<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">tee<\/span> 500_errors.txt<\/p>\n<p><span class=\"token comment\"># 4. \u7edf\u8ba1\u8fd9\u4e9b\u9519\u8bef\u662f\u7531\u54ea\u4e9b IP \u89e6\u53d1\u7684&#xff0c;\u6309\u6b21\u6570\u6392\u5e8f<\/span><br \/>\n<span class=\"token function\">grep<\/span> <span class=\"token string\">&#039;&#034; 500 &#039;<\/span> access.log <span class=\"token operator\">|<\/span> <span class=\"token function\">awk<\/span> <span class=\"token string\">&#039;{print $1}&#039;<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">sort<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">uniq<\/span> <span class=\"token parameter variable\">-c<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">sort<\/span> <span class=\"token parameter variable\">-rn<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">head<\/span><\/p>\n<p><span class=\"token comment\"># 5. \u9519\u8bef\u8bf7\u6c42\u548c\u6b63\u5e38\u6d41\u91cf\u5206\u5f00\u5f52\u6863&#xff08;\u91cd\u5b9a\u5411\u5206\u79bb&#xff09;<\/span><br \/>\n<span class=\"token function\">grep<\/span> <span class=\"token string\">&#039;&#034; 500 &#039;<\/span> access.log <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">500<\/span>.log<br \/>\n<span class=\"token function\">grep<\/span> <span class=\"token parameter variable\">-v<\/span> <span class=\"token string\">&#039;&#034; 500 &#039;<\/span> access.log <span class=\"token operator\">&gt;<\/span> normal.log<\/p>\n<p>\u8fd9\u5957\u7ec4\u5408\u62f3\u5c31\u662f Linux \u65e5\u5fd7\u5904\u7406\u7684\u6838\u5fc3\u601d\u8def&#xff1a;grep \u8d1f\u8d23&#034;\u627e&#034;&#xff0c;sed \u8d1f\u8d23&#034;\u6539&#034;&#xff0c;awk \u8d1f\u8d23&#034;\u7b97&#034;&#xff0c;\u91cd\u5b9a\u5411\u548c\u7ba1\u9053\u8d1f\u8d23&#034;\u4e32\u8054\u4e0e\u843d\u76d8&#034;\u3002<\/p>\n<hr \/>\n<h3>\u4e5d\u3001\u672c\u7bc7\u5c0f\u7ed3<\/h3>\n<table>\n<tr>\u77e5\u8bc6\u70b9\u6838\u5fc3\u5185\u5bb9<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">\u4e09\u79cd\u6570\u636e\u6d41<\/td>\n<td align=\"left\">0 \u6807\u51c6\u8f93\u5165\u30011 \u6807\u51c6\u8f93\u51fa\u30012 \u6807\u51c6\u9519\u8bef&#xff0c;\u9ed8\u8ba4\u5206\u522b\u6307\u5411\u952e\u76d8\u548c\u7ec8\u7aef<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u8f93\u51fa\u91cd\u5b9a\u5411<\/td>\n<td align=\"left\">&gt; \u8986\u76d6\u3001&gt;&gt; \u8ffd\u52a0\u30012&gt; \u91cd\u5b9a\u5411\u9519\u8bef\u3001&amp;&gt; \/ 2&gt;&amp;1 \u5408\u5e76\u8f93\u51fa<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u8f93\u5165\u91cd\u5b9a\u5411<\/td>\n<td align=\"left\">&lt; \u4ece\u6587\u4ef6\u8bfb\u5165\u3001&lt;&lt; \u6b64\u5904\u6587\u6863<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u7ba1\u9053\u4e0e tee<\/td>\n<td align=\"left\">&#096;<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">grep<\/td>\n<td align=\"left\">\u6309\u884c\u8fc7\u6ee4&#xff0c;-v\/-n\/-c\/-i\/-E \u9ad8\u9891\u9009\u9879&#xff0c;\u914d\u5408\u6b63\u5219\u7cbe\u786e\u5339\u914d<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">sed<\/td>\n<td align=\"left\">\u6d41\u5f0f\u7f16\u8f91&#xff0c;s\/old\/new\/g \u66ff\u6362&#xff0c;d \u5220\u9664&#xff0c;-i \u843d\u76d8\u524d\u5148\u9884\u89c8<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">awk<\/td>\n<td align=\"left\">\u6309\u5217\u5904\u7406&#xff0c;-F \u6307\u5b9a\u5206\u9694\u7b26&#xff0c;$1 \u53d6\u5217&#xff0c;\u652f\u6301\u6570\u7ec4\u7edf\u8ba1\u4e0e\u6c47\u603b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u638c\u63e1\u8fd9\u4e9b\u547d\u4ee4\u540e&#xff0c;\u9762\u5bf9\u4efb\u4f55\u65e5\u5fd7\u6587\u4ef6\u90fd\u80fd\u5feb\u901f\u5b8c\u6210&#034;\u68c0\u7d22 \u2192 \u8fc7\u6ee4 \u2192 \u7edf\u8ba1 \u2192 \u5f52\u6863&#034;\u7684\u5b8c\u6574\u5904\u7406\u6d41\u7a0b&#xff0c;\u8fd9\u4e5f\u662f SRE\/\u8fd0\u7ef4\u65e5\u5e38\u6392\u969c\u7684\u57fa\u672c\u529f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux \u6807\u51c6 IO&#xff08;\u8f93\u5165\/\u8f93\u51fa&#xff09;\u4e0e\u65e5\u5fd7\u6587\u4ef6\u5904\u7406\u7ee7\u4e0a\u4e00\u7bc7\u300a\u76ee\u5f55\u3001\u914d\u7f6e\u6587\u4ef6\u4e0e\u65e5\u5fd7\u6587\u4ef6\u7ba1\u7406\u300b&#xff08;pwd\u3001cp \u7b49\u547d\u4ee4&#xff09;\u4e4b\u540e&#xff0c;\u672c\u7bc7\u8bb2\u89e3 Linux \u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u4e2a\u57fa\u7840\u6982\u5ff5\u2014\u2014\u6807\u51c6 IO&#xff0c;\u4ee5\u53ca\u56f4\u7ed5\u5b83\u884d\u751f\u51fa\u7684\u91cd\u5b9a\u5411\u3001\u7ba1\u9053\u548c\u4e09\u5927\u6587\u672c\u5904\u7406\u5de5\u5177&#xff08;grep \/ sed \/ awk&#xff09;\u3002\u8fd9\u4e9b\u5185\u5bb9\u662f\u540e\u7eed\u505a\u65e5\u5fd7\u5206\u6790\u3001\u6545\u969c\u6392\u67e5\u548c Shell \u811a\u672c\u7f16\u5199\u7684\u5730\u57fa\u3002\u4e00\u3001\u6807\u51c6 IO&#xff1a;\u4e09\u79cd<\/p>\n","protected":false},"author":2,"featured_media":112110,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11653,58,103,44],"topic":[],"class_list":["post-112116","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-11653","tag-linux","tag-ubuntu","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Day6 Linux\u6807\u51c6IO\u4e0e\u65e5\u5fd7\u6587\u4ef6\u5904\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/112116.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Day6 Linux\u6807\u51c6IO\u4e0e\u65e5\u5fd7\u6587\u4ef6\u5904\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Linux \u6807\u51c6 IO&#xff08;\u8f93\u5165\/\u8f93\u51fa&#xff09;\u4e0e\u65e5\u5fd7\u6587\u4ef6\u5904\u7406\u7ee7\u4e0a\u4e00\u7bc7\u300a\u76ee\u5f55\u3001\u914d\u7f6e\u6587\u4ef6\u4e0e\u65e5\u5fd7\u6587\u4ef6\u7ba1\u7406\u300b&#xff08;pwd\u3001cp \u7b49\u547d\u4ee4&#xff09;\u4e4b\u540e&#xff0c;\u672c\u7bc7\u8bb2\u89e3 Linux \u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u4e2a\u57fa\u7840\u6982\u5ff5\u2014\u2014\u6807\u51c6 IO&#xff0c;\u4ee5\u53ca\u56f4\u7ed5\u5b83\u884d\u751f\u51fa\u7684\u91cd\u5b9a\u5411\u3001\u7ba1\u9053\u548c\u4e09\u5927\u6587\u672c\u5904\u7406\u5de5\u5177&#xff08;grep \/ sed \/ awk&#xff09;\u3002\u8fd9\u4e9b\u5185\u5bb9\u662f\u540e\u7eed\u505a\u65e5\u5fd7\u5206\u6790\u3001\u6545\u969c\u6392\u67e5\u548c Shell \u811a\u672c\u7f16\u5199\u7684\u5730\u57fa\u3002\u4e00\u3001\u6807\u51c6 IO&#xff1a;\u4e09\u79cd\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/112116.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-02T10:24:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261002102451-6abf8673433e3.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/112116.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/112116.html\",\"name\":\"Day6 Linux\u6807\u51c6IO\u4e0e\u65e5\u5fd7\u6587\u4ef6\u5904\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-02T10:24:52+00:00\",\"dateModified\":\"2026-10-02T10:24:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/112116.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/112116.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/112116.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Day6 Linux\u6807\u51c6IO\u4e0e\u65e5\u5fd7\u6587\u4ef6\u5904\u7406\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Day6 Linux\u6807\u51c6IO\u4e0e\u65e5\u5fd7\u6587\u4ef6\u5904\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/112116.html","og_locale":"zh_CN","og_type":"article","og_title":"Day6 Linux\u6807\u51c6IO\u4e0e\u65e5\u5fd7\u6587\u4ef6\u5904\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Linux \u6807\u51c6 IO&#xff08;\u8f93\u5165\/\u8f93\u51fa&#xff09;\u4e0e\u65e5\u5fd7\u6587\u4ef6\u5904\u7406\u7ee7\u4e0a\u4e00\u7bc7\u300a\u76ee\u5f55\u3001\u914d\u7f6e\u6587\u4ef6\u4e0e\u65e5\u5fd7\u6587\u4ef6\u7ba1\u7406\u300b&#xff08;pwd\u3001cp \u7b49\u547d\u4ee4&#xff09;\u4e4b\u540e&#xff0c;\u672c\u7bc7\u8bb2\u89e3 Linux \u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u4e2a\u57fa\u7840\u6982\u5ff5\u2014\u2014\u6807\u51c6 IO&#xff0c;\u4ee5\u53ca\u56f4\u7ed5\u5b83\u884d\u751f\u51fa\u7684\u91cd\u5b9a\u5411\u3001\u7ba1\u9053\u548c\u4e09\u5927\u6587\u672c\u5904\u7406\u5de5\u5177&#xff08;grep \/ sed \/ awk&#xff09;\u3002\u8fd9\u4e9b\u5185\u5bb9\u662f\u540e\u7eed\u505a\u65e5\u5fd7\u5206\u6790\u3001\u6545\u969c\u6392\u67e5\u548c Shell \u811a\u672c\u7f16\u5199\u7684\u5730\u57fa\u3002\u4e00\u3001\u6807\u51c6 IO&#xff1a;\u4e09\u79cd","og_url":"https:\/\/www.wsisp.com\/helps\/112116.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-02T10:24:52+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261002102451-6abf8673433e3.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/112116.html","url":"https:\/\/www.wsisp.com\/helps\/112116.html","name":"Day6 Linux\u6807\u51c6IO\u4e0e\u65e5\u5fd7\u6587\u4ef6\u5904\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-02T10:24:52+00:00","dateModified":"2026-10-02T10:24:52+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/112116.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/112116.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/112116.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Day6 Linux\u6807\u51c6IO\u4e0e\u65e5\u5fd7\u6587\u4ef6\u5904\u7406"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/112116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=112116"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/112116\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/112110"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=112116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=112116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=112116"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=112116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}