{"id":119,"date":"2014-06-25T02:38:50","date_gmt":"2014-06-25T02:38:50","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=119"},"modified":"2014-06-25T02:38:50","modified_gmt":"2014-06-25T02:38:50","slug":"linux-shell%e4%b8%ad%e7%9a%84%e7%89%b9%e6%ae%8a%e5%ad%97%e7%ac%a6","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/119.html","title":{"rendered":"Linux Shell\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26"},"content":{"rendered":"<h4 style=\"color: #454545;\">\u4e00\u3001\u901a\u914d\u7b26<\/h4>\n<h6 style=\"color: #454545;\">1\uff0e\u4e00\u822c\u901a\u914d\u7b26<\/h6>\n<div style=\"color: #454545;\">*\uff08\u661f\u53f7\uff09\uff0c\u5b83\u5339\u914d\u4efb\u610f\u5b57\u7b26\u76840\u6b21\u6216\u591a\u6b21\u51fa\u73b0<\/div>\n<div style=\"color: #454545;\">?\uff08\u95ee\u53f7\uff09\uff0c\u5b83\u5339\u914d\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26<\/div>\n<div style=\"color: #454545;\">[\u00a0]\uff08\u4e00\u5bf9\u65b9\u62ec\u53f7\uff09\uff0c\u5176\u4e2d\u6709\u4e00\u4e2a\u5b57\u7b26\u7ec4\u3002\u5176\u4f5c\u7528\u662f\u5339\u914d\u8be5\u5b57\u7b26\u7ec4\u6240\u9650\u5b9a\u7684\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26<\/div>\n<div style=\"color: #454545;\">!\uff08\u60ca\u53f9\u53f7\uff09\uff0c\u5982\u679c\u5b83\u7d27\u8ddf\u5728\u4e00\u5bf9\u65b9\u62ec\u53f7\u7684\u5de6\u65b9\u62ec\u53f7\uff08[\uff09\u4e4b\u540e\uff0c\u5219\u8868\u793a\u4e0d\u5728\u4e00\u5bf9\u65b9\u62ec\u53f7\u4e2d\u6240\u5217\u51fa\u7684\u5b57\u7b26<\/div>\n<h6 style=\"color: #454545;\">2\uff0e\u6a21\u5f0f\u8868\u8fbe\u5f0f\u00a0\u2014\u2014\u662f\u90a3\u4e9b\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u901a\u914d\u7b26\u7684\u5b57<\/h6>\n<div style=\"color: #454545;\">*(\u6a21\u5f0f\u8868)\u2014\u2014\u5339\u914d\u7ed9\u5b9a\u6a21\u5f0f\u8868\u4e2d\u201c\u6a21\u5f0f\u201d\u76840\u6b21\u6216\u591a\u6b21\u51fa\u73b0\uff0c\u5404\u6a21\u5f0f\u4e4b\u95f4\u4ee5\u201c\uff5c\u201d\u5206\u5f00\uff08\u4e0b\u540c\uff09<\/div>\n<div style=\"color: #454545;\">+(\u6a21\u5f0f\u8868)\u2014\u2014\u5339\u914d\u7ed9\u5b9a\u6a21\u5f0f\u8868\u4e2d\u201c\u6a21\u5f0f\u201d\u76841\u6b21\u6216\u591a\u6b21\u51fa\u73b0<\/div>\n<div style=\"color: #454545;\">?(\u6a21\u5f0f\u8868)\u2014\u2014\u5339\u914d\u6a21\u5f0f\u8868\u4e2d\u4efb\u4f55\u4e00\u79cd\u201c\u6a21\u5f0f\u201d\u76840\u6b21\u62161\u6b21\u51fa\u73b0<\/div>\n<div style=\"color: #454545;\">@(\u6a21\u5f0f\u8868)\u2014\u2014\u4ec5\u5339\u914d\u6a21\u5f0f\u8868\u4e2d\u7ed9\u5b9a\u201c\u6a21\u5f0f\u201d\u7684\u4e00\u6b21\u51fa\u73b0<\/div>\n<div style=\"color: #454545;\">!(\u6a21\u5f0f\u8868)\u2014\u2014\u9664\u7ed9\u5b9a\u6a21\u5f0f\u8868\u4e2d\u7684\u4e00\u4e2a\u201c\u6a21\u5f0f\u201d\u4e4b\u5916\uff0c\u53ef\u4ee5\u5339\u914d\u5176\u4ed6\u4efb\u4f55\u4e1c\u897f<\/div>\n<h4 style=\"color: #454545;\">\u4e8c\u3001\u5f15\u53f7<\/h4>\n<h6 style=\"color: #454545;\">1\uff0e\u53cc\u5f15\u53f7<\/h6>\n<div style=\"color: #454545;\">\u7531\u53cc\u5f15\u53f7\u62ec\u8d77\u6765\u7684\u5b57\u7b26\uff08\u9664$\u3001\u5012\u5f15\u53f7\uff08`\uff09\u548c\u53cd\u659c\u7ebf\uff08\uff09\u5916\uff09\u5747\u4f5c\u4e3a\u666e\u901a\u5b57\u7b26\u5bf9\u5f85\u3002<\/div>\n<h6 style=\"color: #454545;\">2\uff0e\u5355\u5f15\u53f7<\/h6>\n<div style=\"color: #454545;\"><span style=\"color: #ff0000;\">\u7531\u5355\u5f15\u53f7\u62ec\u8d77\u6765\u7684\u5b57\u7b26\u90fd\u4f5c\u4e3a\u666e\u901a\u5b57\u7b26\u51fa\u73b0<\/span><\/div>\n<h6 style=\"color: #454545;\">3\uff0e\u5012\u5f15\u53f7<\/h6>\n<div style=\"color: #454545;\">\u5012\u5f15\u53f7\u62ec\u8d77\u6765\u7684\u5b57\u7b26\u4e32\u88abshell\u89e3\u91ca\u4e3a\u547d\u4ee4\u884c\uff0c\u5728\u6267\u884c\u65f6\uff0cshell\u4f1a\u5148\u6267\u884c\u8be5\u547d\u4ee4\u884c\uff0c\u5e76\u4ee5\u5b83\u7684\u6807\u51c6\u8f93\u51fa\u7ed3\u679c\u53d6\u4ee3\u6574\u4e2a\u5012\u5f15\u53f7\u90e8\u5206\u3002<\/div>\n<div style=\"color: #454545;\">\u5012\u5f15\u53f7\u8fd8\u53ef\u4ee5\u5d4c\u5957\u4f7f\u7528\u3002\u4f46\u5e94\u6ce8\u610f\uff0c\u5d4c\u5957\u4f7f\u7528\u65f6\u5185\u5c42\u7684\u5012\u5f15\u53f7\u5fc5\u987b\u7528\u53cd\u659c\u7ebf\uff08\uff09\u5c06\u5176\u8f6c\u4e49\u3002<\/div>\n<h4 style=\"color: #454545;\">\u4e09\u3001\u8f93\u5165\/\u8f93\u51fa\u91cd\u5b9a\u5411\u7b26<\/h4>\n<div style=\"color: #454545;\">\u81ea\u52a8\u6253\u5f00\u4e09\u4e2a\u6807\u51c6\u6587\u4ef6\uff0c\u5373\u6807\u51c6\u8f93\u5165\u6587\u4ef6\uff08stdin\uff09\uff0c\u6807\u51c6\u8f93\u51fa\u6587\u4ef6\uff08stdout\uff09\u548c\u6807\u51c6\u51fa\u9519\u8f93\u51fa\u6587\u4ef6\uff08stderr\uff09\u3002<\/div>\n<h6 style=\"color: #454545;\">1\uff0e\u8f93\u5165\u91cd\u5b9a\u5411\u7b26<\/h6>\n<div style=\"color: #454545;\">\u00a0\u4e00\u822c\u5f62\u5f0f\u662f\uff1a\u547d\u4ee4\u00a0&lt; \u6587\u4ef6\u540d\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5982\uff1a$\u00a0\u00a0score\u00a0&lt;\u00a0file1<\/div>\n<h6 style=\"color: #454545;\">2\uff0e\u8f93\u51fa\u91cd\u5b9a\u5411\u7b26<\/h6>\n<div style=\"color: #454545;\">\u4e00\u822c\u5f62\u5f0f\u662f\uff1a\u547d\u4ee4\u00a0&gt; \u6587\u4ef6\u540d\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5982\uff1a$\u00a0who\u00a0&gt;\u00a0abc<\/div>\n<h6 style=\"color: #454545;\">3\uff0e\u8f93\u51fa\u9644\u52a0\u5b9a\u5411\u7b26<\/h6>\n<div style=\"color: #454545;\">\u4e00\u822c\u5f62\u5f0f\u662f\uff1a\u547d\u4ee4&gt;&gt;\u6587\u4ef6\u540d\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5982\uff1a$\u00a0ps\u00a0-l\u00a0&gt;&gt;\u00a0psfile<\/div>\n<div style=\"color: #454545;\"><\/div>\n<div style=\"color: #454545;\">\u8f93\u5165\u548c\u8f93\u51fa\u91cd\u65b0\u5b9a\u5411\u53ef\u4ee5\u8fde\u5728\u4e00\u8d77\u4f7f\u7528\u3002\u4f8b\u5982\uff1a<\/div>\n<div style=\"color: #454545;\">\n<pre class=\"lang:default decode:true\">$ wc -l &lt;infile &gt;outfile<\/pre>\n<\/div>\n<h6 style=\"color: #454545;\">4\uff0e\u5373\u65f6\u6587\u4ef6\uff08Here\u00a0Document\uff09\u5b9a\u5411\u7b26<\/h6>\n<div style=\"color: #454545;\">\u5373\u65f6\u6587\u4ef6\u7684\u5f62\u5f0f\u662f\uff1a<\/div>\n<div style=\"color: #454545;\"><\/div>\n<blockquote>\n<div style=\"color: #454545;\">\u00a0\u00a0\u00a0\u547d\u4ee4\u00a0\u00a0\uff3b\u53c2\u6570\uff3d&lt;&lt;\u00a0\u6807\u8bb0\u7b26<\/div>\n<div style=\"color: #454545;\">\u00a0 \u00a0\u8f93\u5165\u884c<\/div>\n<div style=\"color: #454545;\">\u00a0\u00a0\u00a0\u00a0\u2026<\/div>\n<div style=\"color: #454545;\">\u00a0\u00a0\u00a0\u6807\u8bb0\u7b26<\/div>\n<\/blockquote>\n<div style=\"color: #454545;\"><span style=\"color: #ff0000;\"><strong>\u6ce8\u610f\uff1a\u6807\u8bb0\u7b26\u8981\u6210\u5bf9\u51fa\u73b0<\/strong><\/span><\/div>\n<div style=\"color: #454545;\">\u4f8b\u5982\uff1a<\/div>\n<div style=\"color: #454545;\">\n<pre class=\"lang:default decode:true\"># mail\u00a0\u00a0$1\u00a0&lt;&lt;\u00a0!!\n\u00a0\u00a0Best\u00a0\u00a0wishes\u00a0\u00a0to\u00a0\u00a0you\u00a0\u00a0on\u00a0\u00a0your\u00a0\u00a0birthday\u00a0.\n\u00a0\u00a0!!<\/pre>\n<\/div>\n<h6 style=\"color: #454545;\">5\uff0e\u4e0e\u6587\u4ef6\u63cf\u8ff0\u5b57\u6709\u5173\u7684\u91cd\u5b9a\u5411<\/h6>\n<div style=\"color: #454545;\">\u2022\u7cfb\u7edf\u4e3a\u6bcf\u4e2a\u8fdb\u7a0b\u81ea\u52a8\u6253\u5f00\u4e09\u4e2a\u6807\u51c6\u6587\u4ef6\uff08\u5373\u6807\u51c6\u8f93\u5165\u3001\u6807\u51c6\u8f93\u51fa\u548c\u9519\u8bef\u8f93\u51fa\uff09\uff0c\u5176\u6587\u4ef6\u63cf\u8ff0\u5b57\u5206\u522b\u4e3a0\uff0c1\u548c2\u3002<\/div>\n<div style=\"color: #454545;\"><\/div>\n<div style=\"color: #454545;\">\u2022\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u4e5f\u53ef\u91cd\u5b9a\u5411\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5176\u4e00\u822c\u5f62\u5f0f\u662f\uff1a<\/div>\n<div style=\"color: #454545;\">\n<pre class=\"lang:default decode:true\">$ \u547d\u4ee4 2&gt;\u6587\u4ef6\u540d\n$ \u547d\u4ee4 2&gt;&gt;\u6587\u4ef6\u540d<\/pre>\n<\/div>\n<div style=\"color: #454545;\">\u2022\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u53ef\u4ee5\u91cd\u5b9a\u5411\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\uff0c\u4e00\u822c\u5f62\u5f0f\u662f\uff1a<\/div>\n<div style=\"color: #454545;\">\n<pre class=\"lang:default decode:true\">$ command $&gt;file<\/pre>\n<\/div>\n<div style=\"color: #454545;\">\u2022\u7b49\u4ef7\u4e8e\u4e0b\u9762\u5f62\u5f0f\u7684\u547d\u4ee4\uff1a<\/div>\n<div style=\"color: #454545;\">\n<pre class=\"lang:default decode:true\">$ command &gt; file 2&gt;&amp;1<\/pre>\n<hr \/>\n<\/div>\n<h4 style=\"color: #454545;\">\u56db\u3001\u6ce8\u91ca\u3001\u7ba1\u9053\u7ebf\u548c\u540e\u53f0\u547d\u4ee4<\/h4>\n<h6 style=\"color: #454545;\">1\uff0e\u6ce8\u91ca<\/h6>\n<div style=\"color: #454545;\">\n<pre class=\"lang:default decode:true\">#!\/bin\/bash\n# If no arguments, then listing the current directory.\n# Otherwise, listing each subdirectory.<\/pre>\n<\/div>\n<h6 style=\"color: #454545;\">2\uff0e\u7ba1\u9053\u7ebf<\/h6>\n<div style=\"color: #454545;\">\n<pre class=\"lang:default decode:true\">$ ls -l $HOME | wc -l\n$ ls | grep m?.c | wc -l<\/pre>\n<\/div>\n<h6 style=\"color: #454545;\">3\uff0e\u540e\u53f0\u547d\u4ee4<\/h6>\n<div style=\"color: #454545;\">\n<pre class=\"lang:default decode:true\">$ gcc m1.c &amp;<\/pre>\n<hr \/>\n<\/div>\n<h4 style=\"color: #454545;\">\u4e94\u3001\u547d\u4ee4\u6267\u884c\u64cd\u4f5c\u7b26<\/h4>\n<h6 style=\"color: #454545;\">1\uff0e\u987a\u5e8f\u6267\u884c<\/h6>\n<div style=\"color: #454545;\">\u5728\u6267\u884c\u65f6\uff0c\u4ee5\u5206\u53f7\u9694\u5f00\u7684\u5404\u6761\u547d\u4ee4\u4ece\u5de6\u5230\u53f3\u4f9d\u6b21\u6267\u884c\uff1a<\/div>\n<div style=\"color: #454545;\">pwd\u00a0;\u00a0\u00a0who\u00a0|\u00a0wc\u00a0\u00a0-l\u00a0;\u00a0\u00a0cd\u00a0\u00a0\/usr\/bin<\/div>\n<h6 style=\"color: #454545;\">2\uff0e\u903b\u8f91\u4e0e<\/h6>\n<div style=\"color: #454545;\">\u547d\u4ee41\u00a0&amp;&amp;\u00a0\u547d\u4ee42<\/div>\n<div style=\"color: #454545;\">\u5176\u529f\u80fd\u662f\uff0c\u5148\u6267\u884c\u547d\u4ee41\uff0c\u5982\u679c\u6267\u884c\u6210\u529f\uff0c\u624d\u6267\u884c\u547d\u4ee42\uff1b\u5426\u5219\uff0c\u82e5\u547d\u4ee41\u6267\u884c\u4e0d\u6210\u529f\uff0c\u5219\u4e0d\u6267\u884c\u547d\u4ee42\u3002<\/div>\n<h6 style=\"color: #454545;\">3\uff0e\u903b\u8f91\u6216<\/h6>\n<div style=\"color: #454545;\">\u547d\u4ee41\u00a0||\u00a0\u547d\u4ee42<\/div>\n<div style=\"color: #454545;\">\u5176\u529f\u80fd\u662f\uff0c\u5148\u6267\u884c\u547d\u4ee41\uff0c\u5982\u679c\u6267\u884c\u4e0d\u6210\u529f\uff0c\u5219\u6267\u884c\u547d\u4ee42\uff1b\u5426\u5219\uff0c\u82e5\u547d\u4ee41\u6267\u884c\u6210\u529f\uff0c\u5219\u4e0d\u6267\u884c\u547d\u4ee42\u3002<\/p>\n<hr \/>\n<\/div>\n<h4 style=\"color: #454545;\">\u516d\u3001\u6210\u7ec4\u547d\u4ee4<\/h4>\n<h6 style=\"color: #454545;\">1\uff0e{\u00a0}\u5f62\u5f0f<\/h6>\n<div style=\"color: #454545;\">\u4ee5\u82b1\u62ec\u53f7\u62ec\u8d77\u6765\u7684\u5168\u90e8\u547d\u4ee4\u53ef\u89c6\u4e3a\u8bed\u6cd5\u4e0a\u7684\u4e00\u6761\u547d\u4ee4\uff0c\u51fa\u73b0\u5728\u7ba1\u9053\u7b26\u7684\u4e00\u8fb9\u3002<\/div>\n<div style=\"color: #454545;\">\n<pre class=\"lang:default decode:true\">$ { echo \"User Report for `date`.\"; who; } | pr<\/pre>\n<\/div>\n<div style=\"color: #454545;\">\u4f7f\u7528\u82b1\u62ec\u53f7\u65f6\u5728\u683c\u5f0f\u4e0a\u5e94\u6ce8\u610f:\u5de6\u62ec\u53f7\u00a0\u201c{\u00a0\u201d\u540e\u9762\u5e94\u6709\u4e00\u4e2a\u7a7a\u683c;\u53f3\u62ec\u53f7\u201c}\u201d\u4e4b\u524d\u5e94\u6709\u4e00\u4e2a\u5206\u53f7\uff08\u00a0;\uff09<\/div>\n<h6 style=\"color: #454545;\">2\uff0e(\u00a0)\u5f62\u5f0f<\/h6>\n<div style=\"color: #454545;\">\n<pre class=\"lang:default decode:true\"> (echo\u00a0\u00a0\"Current\u00a0\u00a0directory\u00a0\u00a0is\u00a0\u00a0`pwd`\u00a0.\u00a0\"\n cp \/home\/iron; ls\u00a0-l;\n cp m1 em1\u00a0&amp;&amp;\u00a0rm m1\n cat em1) | pr<\/pre>\n<\/div>\n<div style=\"color: #454545;\">\u4e8c\u8005\u5b58\u5728\u91cd\u8981\u533a\u522b\uff1a\u7528\u82b1\u62ec\u53f7\u62ec\u8d77\u6765\u7684\u6210\u7ec4\u547d\u4ee4\u53ea\u662f\u5728\u672cshell\u5185\u6267\u884c\u547d\u4ee4\u8868\uff0c\u4e0d\u4ea7\u751f\u65b0\u7684\u8fdb\u7a0b\uff1b\u800c\u7528\u5706\u62ec\u53f7\u62ec\u8d77\u6765\u7684\u6210\u7ec4\u547d\u4ee4\u662f\u5728\u65b0\u7684\u5b50shell\u5185\u6267\u884c\uff0c\u8981\u5efa\u7acb\u65b0\u7684\u5b50\u8fdb\u7a0b\u3002\u56e0\u6b64\uff0c\u5728\u5706\u62ec\u53f7\u5185\u7684\u547d\u4ee4\u4e0d\u4f1a\u6539\u53d8\u7236shell\u7684\u53d8\u91cf\u503c\u53ca\u5de5\u4f5c\u76ee\u5f55\u7b49\u3002<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u901a\u914d\u7b26 1\uff0e\u4e00\u822c\u901a\u914d\u7b26 *\uff08\u661f\u53f7\uff09\uff0c\u5b83\u5339\u914d\u4efb\u610f\u5b57\u7b26\u76840\u6b21\u6216\u591a\u6b21\u51fa\u73b0 ?\uff08\u95ee\u53f7\uff09\uff0c\u5b83\u5339\u914d\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26 [\u00a0] [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[65],"class_list":["post-119","post","type-post","status-publish","format-standard","hentry","category-linux","tag-shell"],"views":2786,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=119"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/119\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}