{"id":38158,"date":"2025-05-19T22:00:58","date_gmt":"2025-05-19T14:00:58","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/38158.html"},"modified":"2025-05-19T22:00:58","modified_gmt":"2025-05-19T14:00:58","slug":"%e6%8e%a2%e7%b4%a2%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%a2%86%e5%9f%9fshell%e8%84%9a%e6%9c%ac%e7%9a%84%e8%84%9a%e6%9c%ac%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84%e6%96%b0%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/38158.html","title":{"rendered":"\u63a2\u7d22\u670d\u52a1\u5668\u9886\u57dfshell\u811a\u672c\u7684\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u65b0\u65b9\u6cd5"},"content":{"rendered":"<h2>\u63a2\u7d22\u670d\u52a1\u5668\u9886\u57dfshell\u811a\u672c\u7684\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u65b0\u65b9\u6cd5<\/h2>\n<p>\u5173\u952e\u8bcd\uff1aShell\u811a\u672c\u3001\u6027\u80fd\u4f18\u5316\u3001\u670d\u52a1\u5668\u7ba1\u7406\u3001\u811a\u672c\u52a0\u901f\u3001Bash\u4f18\u5316\u3001\u5e76\u884c\u5904\u7406\u3001\u8d44\u6e90\u76d1\u63a7<\/p>\n<p>\u6458\u8981\uff1a\u672c\u6587\u6df1\u5165\u63a2\u8ba8\u670d\u52a1\u5668\u73af\u5883\u4e2dShell\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u521b\u65b0\u65b9\u6cd5\u3002\u6211\u4eec\u5c06\u4ece\u57fa\u7840\u539f\u7406\u51fa\u53d1\uff0c\u5206\u6790\u5f71\u54cdShell\u811a\u672c\u6027\u80fd\u7684\u5173\u952e\u56e0\u7d20\uff0c\u4ecb\u7ecd\u4f20\u7edf\u4f18\u5316\u6280\u672f\uff0c\u5e76\u91cd\u70b9\u63a2\u8ba8\u6700\u65b0\u7684\u6027\u80fd\u4f18\u5316\u7b56\u7565\u3002\u6587\u7ae0\u5305\u542b\u8be6\u7ec6\u7684\u4ee3\u7801\u793a\u4f8b\u3001\u6027\u80fd\u6d4b\u8bd5\u6570\u636e\u4ee5\u53ca\u5b9e\u9645\u5e94\u7528\u573a\u666f\uff0c\u5e2e\u52a9\u7cfb\u7edf\u7ba1\u7406\u5458\u548c\u5f00\u53d1\u4eba\u5458\u663e\u8457\u63d0\u5347\u670d\u52a1\u5668\u7ba1\u7406\u811a\u672c\u7684\u6267\u884c\u6548\u7387\u3002\u901a\u8fc7\u7ed3\u5408\u73b0\u4ee3\u670d\u52a1\u5668\u786c\u4ef6\u7279\u6027\u548c\u64cd\u4f5c\u7cfb\u7edf\u65b0\u529f\u80fd\uff0c\u6211\u4eec\u63d0\u51fa\u4e86\u4e00\u7cfb\u5217\u521b\u65b0\u7684\u4f18\u5316\u65b9\u6cd5\uff0c\u5305\u62ec\u5e76\u884c\u5904\u7406\u4f18\u5316\u3001\u5185\u5b58\u7ba1\u7406\u6280\u5de7\u3001I\/O\u64cd\u4f5c\u52a0\u901f\u7b49\uff0c\u4f7f\u8bfb\u8005\u80fd\u591f\u5168\u9762\u638c\u63e1Shell\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u524d\u6cbf\u6280\u672f\u3002<\/p>\n<h3>1. \u80cc\u666f\u4ecb\u7ecd<\/h3>\n<h4>1.1 \u76ee\u7684\u548c\u8303\u56f4<\/h4>\n<p>\u5728\u5f53\u4eca\u7684\u670d\u52a1\u5668\u7ba1\u7406\u9886\u57df\uff0cShell\u811a\u672c\u4ecd\u7136\u662f\u7cfb\u7edf\u7ba1\u7406\u5458\u548cDevOps\u5de5\u7a0b\u5e08\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\u3002\u5c3d\u7ba1Python\u3001Go\u7b49\u73b0\u4ee3\u8bed\u8a00\u5728\u670d\u52a1\u5668\u81ea\u52a8\u5316\u9886\u57df\u8d8a\u6765\u8d8a\u6d41\u884c\uff0c\u4f46Shell\u811a\u672c\u56e0\u5176\u76f4\u63a5\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u4ea4\u4e92\u7684\u80fd\u529b\u3001\u8f7b\u91cf\u7ea7\u7279\u6027\u548c\u5e7f\u6cdb\u7684\u53ef\u79fb\u690d\u6027\uff0c\u4ecd\u7136\u5728\u4f17\u591a\u5173\u952e\u573a\u666f\u4e2d\u5360\u636e\u91cd\u8981\u5730\u4f4d\u3002<\/p>\n<p>\u672c\u6587\u65e8\u5728\u6df1\u5165\u63a2\u8ba8\u670d\u52a1\u5668\u73af\u5883\u4e0bShell\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u521b\u65b0\u65b9\u6cd5\uff0c\u7279\u522b\u5173\u6ce8\uff1a<\/p>\n<li>\u5927\u89c4\u6a21\u670d\u52a1\u5668\u96c6\u7fa4\u7ba1\u7406\u573a\u666f\u4e0b\u7684\u811a\u672c\u6027\u80fd\u74f6\u9888<\/li>\n<li>\u73b0\u4ee3\u670d\u52a1\u5668\u786c\u4ef6\u7279\u6027(\u5982\u591a\u6838CPU\u3001NVMe\u5b58\u50a8)\u5982\u4f55\u5f71\u54cdShell\u811a\u672c\u6027\u80fd<\/li>\n<li>\u64cd\u4f5c\u7cfb\u7edf\u65b0\u529f\u80fd(\u5982cgroups v2\u3001io_uring)\u5728Shell\u811a\u672c\u4f18\u5316\u4e2d\u7684\u5e94\u7528<\/li>\n<li>\u4f20\u7edf\u4f18\u5316\u6280\u672f\u7684\u5c40\u9650\u6027\u53ca\u7a81\u7834\u65b9\u6cd5<\/li>\n<h4>1.2 \u9884\u671f\u8bfb\u8005<\/h4>\n<p>\u672c\u6587\u9002\u5408\u4ee5\u4e0b\u8bfb\u8005\u7fa4\u4f53\uff1a<\/p>\n<li>\u7cfb\u7edf\u7ba1\u7406\u5458\u548cDevOps\u5de5\u7a0b\u5e08\uff1a\u8d1f\u8d23\u670d\u52a1\u5668\u8fd0\u7ef4\u548c\u81ea\u52a8\u5316\u811a\u672c\u5f00\u53d1\u7684\u4e13\u4e1a\u4eba\u5458<\/li>\n<li>\u540e\u7aef\u5f00\u53d1\u5de5\u7a0b\u5e08\uff1a\u9700\u8981\u7f16\u5199\u670d\u52a1\u5668\u90e8\u7f72\u548c\u7ef4\u62a4\u811a\u672c\u7684\u5f00\u53d1\u4eba\u5458<\/li>\n<li>\u6027\u80fd\u4f18\u5316\u4e13\u5bb6\uff1a\u4e13\u6ce8\u4e8e\u7cfb\u7edf\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u6280\u672f\u4eba\u5458<\/li>\n<li>Linux\u6280\u672f\u7231\u597d\u8005\uff1a\u5e0c\u671b\u6df1\u5165\u7406\u89e3Shell\u811a\u672c\u5de5\u4f5c\u539f\u7406\u548c\u4f18\u5316\u6280\u5de7\u7684\u7231\u597d\u8005<\/li>\n<h4>1.3 \u6587\u6863\u7ed3\u6784\u6982\u8ff0<\/h4>\n<p>\u672c\u6587\u9996\u5148\u4ecb\u7ecdShell\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u57fa\u7840\u6982\u5ff5\u548c\u4f20\u7edf\u65b9\u6cd5\uff0c\u7136\u540e\u6df1\u5165\u63a2\u8ba8\u521b\u65b0\u7684\u4f18\u5316\u6280\u672f\u3002\u6211\u4eec\u5c06\u901a\u8fc7\u5b9e\u9645\u4ee3\u7801\u793a\u4f8b\u5c55\u793a\u6bcf\u79cd\u4f18\u5316\u65b9\u6cd5\u7684\u6548\u679c\uff0c\u5e76\u63d0\u4f9b\u6027\u80fd\u5bf9\u6bd4\u6570\u636e\u3002\u6587\u7ae0\u6700\u540e\u5c06\u8ba8\u8bba\u8fd9\u4e9b\u4f18\u5316\u6280\u672f\u5728\u771f\u5b9e\u670d\u52a1\u5668\u73af\u5883\u4e2d\u7684\u5e94\u7528\u6848\u4f8b\u3002<\/p>\n<h4>1.4 \u672f\u8bed\u8868<\/h4>\n<h5>1.4.1 \u6838\u5fc3\u672f\u8bed\u5b9a\u4e49<\/h5>\n<li>Shell\u811a\u672c\uff1a\u7531Shell\u89e3\u91ca\u5668\u6267\u884c\u7684\u811a\u672c\u7a0b\u5e8f\uff0c\u901a\u5e38\u7528\u4e8e\u81ea\u52a8\u5316\u7cfb\u7edf\u7ba1\u7406\u4efb\u52a1<\/li>\n<li>\u6027\u80fd\u4f18\u5316\uff1a\u901a\u8fc7\u6539\u8fdb\u4ee3\u7801\u7ed3\u6784\u3001\u7b97\u6cd5\u6216\u7cfb\u7edf\u914d\u7f6e\u6765\u63d0\u9ad8\u7a0b\u5e8f\u6267\u884c\u6548\u7387\u7684\u8fc7\u7a0b<\/li>\n<li>\u5e76\u884c\u5904\u7406\uff1a\u540c\u65f6\u4f7f\u7528\u591a\u4e2a\u8ba1\u7b97\u8d44\u6e90(\u5982CPU\u6838\u5fc3)\u6765\u52a0\u901f\u4efb\u52a1\u6267\u884c\u7684\u6280\u672f<\/li>\n<li>I\/O\u7ed1\u5b9a\uff1a\u7a0b\u5e8f\u6027\u80fd\u4e3b\u8981\u53d7\u8f93\u5165\/\u8f93\u51fa\u64cd\u4f5c\u9650\u5236\u7684\u60c5\u51b5<\/li>\n<li>CPU\u7ed1\u5b9a\uff1a\u7a0b\u5e8f\u6027\u80fd\u4e3b\u8981\u53d7CPU\u8ba1\u7b97\u80fd\u529b\u9650\u5236\u7684\u60c5\u51b5<\/li>\n<h5>1.4.2 \u76f8\u5173\u6982\u5ff5\u89e3\u91ca<\/h5>\n<li>Bash\uff1a\u6700\u5e38\u7528\u7684Unix Shell\u4e4b\u4e00\uff0c\u672c\u6587\u4e3b\u8981\u57fa\u4e8eBash\u8fdb\u884c\u8ba8\u8bba<\/li>\n<li>Zsh\uff1a\u53e6\u4e00\u79cd\u6d41\u884c\u7684Shell\uff0c\u5177\u6709\u6bd4Bash\u66f4\u4e30\u5bcc\u7684\u529f\u80fd<\/li>\n<li>\u8fdb\u7a0b\u66ff\u6362\uff1aShell\u4e2d\u7684\u4e00\u79cd\u9ad8\u7ea7\u7279\u6027\uff0c\u5141\u8bb8\u5c06\u547d\u4ee4\u8f93\u51fa\u4f5c\u4e3a\u6587\u4ef6\u5904\u7406<\/li>\n<li>\u534f\u7a0b\uff1a\u8f7b\u91cf\u7ea7\u7684\u5e76\u53d1\u6267\u884c\u5355\u5143\uff0c\u6bd4\u7ebf\u7a0b\u66f4\u9ad8\u6548<\/li>\n<li>\u7f13\u5b58\u53cb\u597d\uff1a\u4ee3\u7801\u8bbe\u8ba1\u8003\u8651CPU\u7f13\u5b58\u7279\u6027\u4ee5\u63d0\u9ad8\u6027\u80fd<\/li>\n<h5>1.4.3 \u7f29\u7565\u8bcd\u5217\u8868<\/h5>\n<li>CLI\uff1aCommand Line Interface\uff0c\u547d\u4ee4\u884c\u754c\u9762<\/li>\n<li>IPC\uff1aInter-Process Communication\uff0c\u8fdb\u7a0b\u95f4\u901a\u4fe1<\/li>\n<li>FIFO\uff1aFirst In First Out\uff0c\u547d\u540d\u7ba1\u9053<\/li>\n<li>SSD\uff1aSolid State Drive\uff0c\u56fa\u6001\u786c\u76d8<\/li>\n<li>NVMe\uff1aNon-Volatile Memory Express\uff0c\u9ad8\u6027\u80fd\u5b58\u50a8\u534f\u8bae<\/li>\n<h3>2. \u6838\u5fc3\u6982\u5ff5\u4e0e\u8054\u7cfb<\/h3>\n<p>Shell\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u6838\u5fc3\u5728\u4e8e\u7406\u89e3\u811a\u672c\u6267\u884c\u7684\u751f\u547d\u5468\u671f\u548c\u8d44\u6e90\u6d88\u8017\u6a21\u5f0f\u3002\u4e0b\u56fe\u5c55\u793a\u4e86Shell\u811a\u672c\u6267\u884c\u7684\u4e3b\u8981\u9636\u6bb5\u548c\u6027\u80fd\u5f71\u54cd\u56e0\u7d20\uff1a<\/p>\n<p>  #mermaid-svg-9lJCEV8J5GkmsfVt {font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-9lJCEV8J5GkmsfVt .error-icon{fill:#552222;}#mermaid-svg-9lJCEV8J5GkmsfVt .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-9lJCEV8J5GkmsfVt .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-9lJCEV8J5GkmsfVt .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-9lJCEV8J5GkmsfVt .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-9lJCEV8J5GkmsfVt .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-9lJCEV8J5GkmsfVt .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-9lJCEV8J5GkmsfVt .marker{fill:#333333;stroke:#333333;}#mermaid-svg-9lJCEV8J5GkmsfVt .marker.cross{stroke:#333333;}#mermaid-svg-9lJCEV8J5GkmsfVt svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-9lJCEV8J5GkmsfVt .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-9lJCEV8J5GkmsfVt .cluster-label text{fill:#333;}#mermaid-svg-9lJCEV8J5GkmsfVt .cluster-label span{color:#333;}#mermaid-svg-9lJCEV8J5GkmsfVt .label text,#mermaid-svg-9lJCEV8J5GkmsfVt span{fill:#333;color:#333;}#mermaid-svg-9lJCEV8J5GkmsfVt .node rect,#mermaid-svg-9lJCEV8J5GkmsfVt .node circle,#mermaid-svg-9lJCEV8J5GkmsfVt .node ellipse,#mermaid-svg-9lJCEV8J5GkmsfVt .node polygon,#mermaid-svg-9lJCEV8J5GkmsfVt .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-9lJCEV8J5GkmsfVt .node .label{text-align:center;}#mermaid-svg-9lJCEV8J5GkmsfVt .node.clickable{cursor:pointer;}#mermaid-svg-9lJCEV8J5GkmsfVt .arrowheadPath{fill:#333333;}#mermaid-svg-9lJCEV8J5GkmsfVt .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-9lJCEV8J5GkmsfVt .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-9lJCEV8J5GkmsfVt .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-9lJCEV8J5GkmsfVt .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-9lJCEV8J5GkmsfVt .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-9lJCEV8J5GkmsfVt .cluster text{fill:#333;}#mermaid-svg-9lJCEV8J5GkmsfVt .cluster span{color:#333;}#mermaid-svg-9lJCEV8J5GkmsfVt div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-9lJCEV8J5GkmsfVt :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;} <\/p>\n<p>         <span id=\"L-L-A-B\" class=\"edgeLabel L-LS-A\\' L-LE-B\"><\/span> <\/p>\n<p>         <span id=\"L-L-B-C\" class=\"edgeLabel L-LS-B\\' L-LE-C\"><\/span> <\/p>\n<p>         <span id=\"L-L-C-D\" class=\"edgeLabel L-LS-C\\' L-LE-D\"><\/span> <\/p>\n<p>         <span id=\"L-L-D-E\" class=\"edgeLabel L-LS-D\\' L-LE-E\"><\/span> <\/p>\n<p>         <span id=\"L-L-E-F\" class=\"edgeLabel L-LS-E\\' L-LE-F\"><\/span> <\/p>\n<p>         <span id=\"L-L-F-G\" class=\"edgeLabel L-LS-F\\' L-LE-G\"><\/span> <\/p>\n<p>           \u811a\u672c\u542f\u52a8 <\/p>\n<p>           \u89e3\u6790\u9636\u6bb5 <\/p>\n<p>           \u547d\u4ee4\u6267\u884c <\/p>\n<p>           I\/O\u64cd\u4f5c <\/p>\n<p>           \u5185\u5b58\u7ba1\u7406 <\/p>\n<p>           \u8fdb\u7a0b\u7ba1\u7406 <\/p>\n<p>           \u7ed3\u679c\u8f93\u51fa <\/p>\n<p>\u6bcf\u4e2a\u9636\u6bb5\u90fd\u53ef\u80fd\u6210\u4e3a\u6027\u80fd\u74f6\u9888\uff1a<\/p>\n<li>\u89e3\u6790\u9636\u6bb5\uff1a\u590d\u6742\u6761\u4ef6\u5224\u65ad\u548c\u51fd\u6570\u5b9a\u4e49\u4f1a\u589e\u52a0\u89e3\u6790\u65f6\u95f4<\/li>\n<li>\u547d\u4ee4\u6267\u884c\uff1a\u5916\u90e8\u547d\u4ee4\u8c03\u7528\u5f00\u9500\u3001\u547d\u4ee4\u66ff\u6362\u64cd\u4f5c<\/li>\n<li>I\/O\u64cd\u4f5c\uff1a\u6587\u4ef6\u8bfb\u5199\u3001\u7ba1\u9053\u6570\u636e\u4f20\u8f93<\/li>\n<li>\u5185\u5b58\u7ba1\u7406\uff1a\u53d8\u91cf\u5904\u7406\u3001\u6570\u7ec4\u64cd\u4f5c<\/li>\n<li>\u8fdb\u7a0b\u7ba1\u7406\uff1a\u5b50\u8fdb\u7a0b\u521b\u5efa\u3001\u4fe1\u53f7\u5904\u7406<\/li>\n<li>\u7ed3\u679c\u8f93\u51fa\uff1a\u7ec8\u7aef\u8f93\u51fa\u901f\u5ea6\u3001\u91cd\u5b9a\u5411\u6548\u7387<\/li>\n<p>\u73b0\u4ee3\u670d\u52a1\u5668\u73af\u5883\u4e3aShell\u811a\u672c\u4f18\u5316\u63d0\u4f9b\u4e86\u65b0\u7684\u53ef\u80fd\u6027\uff1a<\/p>\n<li>\u591a\u6838CPU\uff1a\u5141\u8bb8\u5e76\u884c\u6267\u884c\u591a\u4e2a\u547d\u4ee4<\/li>\n<li>\u5927\u5185\u5b58\uff1a\u652f\u6301\u66f4\u9ad8\u6548\u7684\u5185\u5b58\u7f13\u5b58\u7b56\u7565<\/li>\n<li>\u9ad8\u901f\u5b58\u50a8\uff1a\u51cf\u5c11I\/O\u7b49\u5f85\u65f6\u95f4<\/li>\n<li>\u5bb9\u5668\u6280\u672f\uff1a\u63d0\u4f9b\u8d44\u6e90\u9694\u79bb\u548c\u9650\u5236\u80fd\u529b<\/li>\n<h3>3. \u6838\u5fc3\u7b97\u6cd5\u539f\u7406 &amp; \u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4<\/h3>\n<h4>3.1 \u5e76\u884c\u5904\u7406\u4f18\u5316<\/h4>\n<p>\u4f20\u7edfShell\u811a\u672c\u901a\u5e38\u662f\u5355\u7ebf\u7a0b\u6267\u884c\u7684\uff0c\u65e0\u6cd5\u5145\u5206\u5229\u7528\u73b0\u4ee3\u670d\u52a1\u5668\u7684\u591a\u6838CPU\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u5e76\u884c\u5904\u7406\u7684\u51e0\u79cd\u521b\u65b0\u65b9\u6cd5\uff1a<\/p>\n<h5>3.1.1 \u4f7f\u7528GNU Parallel\u66ff\u4ee3xargs<\/h5>\n<p><span class=\"token comment\"># \u4f20\u7edf\u65b9\u5f0f &#8211; \u987a\u5e8f\u5904\u7406<\/span><br \/>\n<span class=\"token function\">find<\/span> <span class=\"token builtin class-name\">.<\/span> -type f -name <span class=\"token string\">\\&#8221;*.log\\&#8221;<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">xargs<\/span> -n <span class=\"token number\">1<\/span> <span class=\"token function\">gzip<\/span><\/p>\n<p><span class=\"token comment\"># \u4f18\u5316\u65b9\u5f0f &#8211; \u5e76\u884c\u5904\u7406<\/span><br \/>\n<span class=\"token function\">find<\/span> <span class=\"token builtin class-name\">.<\/span> -type f -name <span class=\"token string\">\\&#8221;*.log\\&#8221;<\/span> <span class=\"token operator\">|<\/span> parallel -j <span class=\"token variable\"><span class=\"token variable\">$(<\/span>nproc<span class=\"token variable\">)<\/span><\/span> <span class=\"token function\">gzip<\/span> <span class=\"token punctuation\">{<br \/>\n   <\/span><span class=\"token punctuation\">}<\/span><\/p>\n<p>parallel\u547d\u4ee4\u63d0\u4f9b\u4e86\u66f4\u7cbe\u7ec6\u7684\u5e76\u884c\u63a7\u5236\uff1a<\/p>\n<p><span class=\"token comment\"># \u63a7\u5236\u5e76\u884c\u5ea6\uff0c\u4fdd\u7559\u4e00\u4e2a\u6838\u5fc3\u7ed9\u7cfb\u7edf<\/span><br \/>\nparallel -j <span class=\"token variable\"><span class=\"token variable\">$((<\/span> $<span class=\"token punctuation\">(<\/span>nproc<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span> <span class=\"token number\">1<\/span> <span class=\"token variable\">))<\/span><\/span> ::: command1 command2 command3<\/p>\n<p><span class=\"token comment\"># \u4fdd\u6301\u8f93\u51fa\u987a\u5e8f<\/span><br \/>\nparallel -k ::: command1 command2 command3<\/p>\n<p><span class=\"token comment\"># \u8fdb\u5ea6\u663e\u793a<\/span><br \/>\nparallel &#8211;progress ::: command1 command2 command3<\/p>\n<h5>3.1.2 \u534f\u7a0b\u4e0ecoproc<\/h5>\n<p>Bash 4.0+\u652f\u6301\u534f\u7a0b(coproc)\uff0c\u53ef\u4ee5\u521b\u5efa\u8f7b\u91cf\u7ea7\u7684\u5e76\u884c\u6267\u884c\u5355\u5143\uff1a<\/p>\n<p><span class=\"token comment\"># \u521b\u5efa\u534f\u7a0b\u5904\u7406\u6570\u636e<\/span><br \/>\ncoproc PROCESS_DATA <span class=\"token punctuation\">{<br \/>\n   <\/span><br \/>\n    <span class=\"token keyword\">while<\/span> <span class=\"token builtin class-name\">read<\/span> line<span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">do<\/span><br \/>\n        <span class=\"token comment\"># \u590d\u6742\u6570\u636e\u5904\u7406<\/span><br \/>\n        <span class=\"token assign-left variable\">processed_data<\/span><span class=\"token operator\">=<\/span><span class=\"token variable\"><span class=\"token variable\">$(<\/span>complex_processing <span class=\"token string\">\\&#8221;<span class=\"token variable\">$line<\/span>\\&#8221;<\/span><span class=\"token variable\">)<\/span><\/span><br \/>\n        <span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">\\&#8221;<span class=\"token variable\">$processed_data<\/span>\\&#8221;<\/span><br \/>\n    <span class=\"token keyword\">done<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\"># \u4e3b\u8fdb\u7a0b\u63d0\u4f9b\u6570\u636e<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb873\u6b21\uff0c\u70b9\u8d5e20\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\u5728\u5f53\u4eca\u7684\u670d\u52a1\u5668\u7ba1\u7406\u9886\u57df\uff0cShell\u811a\u672c\u4ecd\u7136\u662f\u7cfb\u7edf\u7ba1\u7406\u5458\u548cDevOps\u5de5\u7a0b\u5e08\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\u3002\u5c3d\u7ba1Python\u3001Go\u7b49\u73b0\u4ee3\u8bed\u8a00\u5728\u670d\u52a1\u5668\u81ea\u52a8\u5316\u9886\u57df\u8d8a\u6765\u8d8a\u6d41\u884c\uff0c\u4f46Shell\u811a\u672c\u56e0\u5176\u76f4\u63a5\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u4ea4\u4e92\u7684\u80fd\u529b\u3001\u8f7b\u91cf\u7ea7\u7279\u6027\u548c\u5e7f\u6cdb\u7684\u53ef\u79fb\u690d\u6027\uff0c\u4ecd\u7136\u5728\u4f17\u591a\u5173\u952e\u573a\u666f\u4e2d\u5360\u636e\u91cd\u8981\u5730\u4f4d\u3002\u5927\u89c4\u6a21\u670d\u52a1\u5668\u96c6\u7fa4\u7ba1\u7406\u573a\u666f\u4e0b\u7684\u811a\u672c\u6027\u80fd\u74f6\u9888\u73b0\u4ee3\u670d\u52a1\u5668\u786c\u4ef6\u7279\u6027(\u5982\u591a\u6838CPU\u3001NVMe\u5b58\u50a8)\u5982\u4f55\u5f71\u54cdShell\u811a\u672c\u6027\u80fd\u64cd\u4f5c\u7cfb\u7edf\u65b0\u529f\u80fd(\u5982cgroups v2\u3001io_uring)\u5728Shell\u811a\u672c\u4f18\u5316\u4e2d\u7684\u5e94\u7528\u4f20\u7edf\u4f18\u5316\u6280\u672f\u7684\u5c40\u9650\u6027\u53ca\u7a81\u7834\u65b9\u6cd5\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[66,56,43,44],"topic":[],"class_list":["post-38158","post","type-post","status-publish","format-standard","hentry","category-server","tag-ai","tag-56","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u63a2\u7d22\u670d\u52a1\u5668\u9886\u57dfshell\u811a\u672c\u7684\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u65b0\u65b9\u6cd5 - \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\/38158.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u63a2\u7d22\u670d\u52a1\u5668\u9886\u57dfshell\u811a\u672c\u7684\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u65b0\u65b9\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb873\u6b21\uff0c\u70b9\u8d5e20\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\u5728\u5f53\u4eca\u7684\u670d\u52a1\u5668\u7ba1\u7406\u9886\u57df\uff0cShell\u811a\u672c\u4ecd\u7136\u662f\u7cfb\u7edf\u7ba1\u7406\u5458\u548cDevOps\u5de5\u7a0b\u5e08\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\u3002\u5c3d\u7ba1Python\u3001Go\u7b49\u73b0\u4ee3\u8bed\u8a00\u5728\u670d\u52a1\u5668\u81ea\u52a8\u5316\u9886\u57df\u8d8a\u6765\u8d8a\u6d41\u884c\uff0c\u4f46Shell\u811a\u672c\u56e0\u5176\u76f4\u63a5\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u4ea4\u4e92\u7684\u80fd\u529b\u3001\u8f7b\u91cf\u7ea7\u7279\u6027\u548c\u5e7f\u6cdb\u7684\u53ef\u79fb\u690d\u6027\uff0c\u4ecd\u7136\u5728\u4f17\u591a\u5173\u952e\u573a\u666f\u4e2d\u5360\u636e\u91cd\u8981\u5730\u4f4d\u3002\u5927\u89c4\u6a21\u670d\u52a1\u5668\u96c6\u7fa4\u7ba1\u7406\u573a\u666f\u4e0b\u7684\u811a\u672c\u6027\u80fd\u74f6\u9888\u73b0\u4ee3\u670d\u52a1\u5668\u786c\u4ef6\u7279\u6027(\u5982\u591a\u6838CPU\u3001NVMe\u5b58\u50a8)\u5982\u4f55\u5f71\u54cdShell\u811a\u672c\u6027\u80fd\u64cd\u4f5c\u7cfb\u7edf\u65b0\u529f\u80fd(\u5982cgroups v2\u3001io_uring)\u5728Shell\u811a\u672c\u4f18\u5316\u4e2d\u7684\u5e94\u7528\u4f20\u7edf\u4f18\u5316\u6280\u672f\u7684\u5c40\u9650\u6027\u53ca\u7a81\u7834\u65b9\u6cd5\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/38158.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-19T14:00:58+00:00\" \/>\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=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38158.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/38158.html\",\"name\":\"\u63a2\u7d22\u670d\u52a1\u5668\u9886\u57dfshell\u811a\u672c\u7684\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u65b0\u65b9\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-19T14:00:58+00:00\",\"dateModified\":\"2025-05-19T14:00:58+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/38158.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/38158.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38158.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u63a2\u7d22\u670d\u52a1\u5668\u9886\u57dfshell\u811a\u672c\u7684\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u65b0\u65b9\u6cd5\"}]},{\"@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":"\u63a2\u7d22\u670d\u52a1\u5668\u9886\u57dfshell\u811a\u672c\u7684\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u65b0\u65b9\u6cd5 - \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\/38158.html","og_locale":"zh_CN","og_type":"article","og_title":"\u63a2\u7d22\u670d\u52a1\u5668\u9886\u57dfshell\u811a\u672c\u7684\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u65b0\u65b9\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb873\u6b21\uff0c\u70b9\u8d5e20\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\u5728\u5f53\u4eca\u7684\u670d\u52a1\u5668\u7ba1\u7406\u9886\u57df\uff0cShell\u811a\u672c\u4ecd\u7136\u662f\u7cfb\u7edf\u7ba1\u7406\u5458\u548cDevOps\u5de5\u7a0b\u5e08\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\u3002\u5c3d\u7ba1Python\u3001Go\u7b49\u73b0\u4ee3\u8bed\u8a00\u5728\u670d\u52a1\u5668\u81ea\u52a8\u5316\u9886\u57df\u8d8a\u6765\u8d8a\u6d41\u884c\uff0c\u4f46Shell\u811a\u672c\u56e0\u5176\u76f4\u63a5\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u4ea4\u4e92\u7684\u80fd\u529b\u3001\u8f7b\u91cf\u7ea7\u7279\u6027\u548c\u5e7f\u6cdb\u7684\u53ef\u79fb\u690d\u6027\uff0c\u4ecd\u7136\u5728\u4f17\u591a\u5173\u952e\u573a\u666f\u4e2d\u5360\u636e\u91cd\u8981\u5730\u4f4d\u3002\u5927\u89c4\u6a21\u670d\u52a1\u5668\u96c6\u7fa4\u7ba1\u7406\u573a\u666f\u4e0b\u7684\u811a\u672c\u6027\u80fd\u74f6\u9888\u73b0\u4ee3\u670d\u52a1\u5668\u786c\u4ef6\u7279\u6027(\u5982\u591a\u6838CPU\u3001NVMe\u5b58\u50a8)\u5982\u4f55\u5f71\u54cdShell\u811a\u672c\u6027\u80fd\u64cd\u4f5c\u7cfb\u7edf\u65b0\u529f\u80fd(\u5982cgroups v2\u3001io_uring)\u5728Shell\u811a\u672c\u4f18\u5316\u4e2d\u7684\u5e94\u7528\u4f20\u7edf\u4f18\u5316\u6280\u672f\u7684\u5c40\u9650\u6027\u53ca\u7a81\u7834\u65b9\u6cd5\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/38158.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-19T14:00:58+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/38158.html","url":"https:\/\/www.wsisp.com\/helps\/38158.html","name":"\u63a2\u7d22\u670d\u52a1\u5668\u9886\u57dfshell\u811a\u672c\u7684\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u65b0\u65b9\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-19T14:00:58+00:00","dateModified":"2025-05-19T14:00:58+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/38158.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/38158.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/38158.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u63a2\u7d22\u670d\u52a1\u5668\u9886\u57dfshell\u811a\u672c\u7684\u811a\u672c\u6027\u80fd\u4f18\u5316\u7684\u65b0\u65b9\u6cd5"}]},{"@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\/38158","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=38158"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38158\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=38158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=38158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=38158"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=38158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}