{"id":51968,"date":"2024-12-03T12:25:47","date_gmt":"2024-12-03T04:25:47","guid":{"rendered":"https:\/\/fwq.ai\/blog\/51968\/"},"modified":"2024-12-03T12:25:47","modified_gmt":"2024-12-03T04:25:47","slug":"linux-shell%e7%9a%84%e5%b8%b8%e7%94%a8%e6%93%8d%e4%bd%9c%e6%9c%89%e5%93%aa%e4%ba%9b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/51968\/","title":{"rendered":"Linux\u00a0Shell\u7684\u5e38\u7528\u64cd\u4f5c\u6709\u54ea\u4e9b"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Linux&nbsp;Shell\u7684\u5e38\u7528\u64cd\u4f5c\u6709\u54ea\u4e9b<\/h1>\n<p>\u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aLinux&nbsp;Shell\u7684\u5e38\u7528\u64cd\u4f5c\u6709\u54ea\u4e9b\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b<\/p>\n<ul>\n<ul><\/ul>\n<\/ul>\n<h3>Linux\u30111 Shell<\/h3>\n<h4>1. \u8bed\u5f55<\/h4>\n<p>\u8ba1\u7b97\u673a\u4e0d\u4ec5\u4ec5\u7528\u6765\u5f00\u53d1\u4e2a\u7f51\u7ad9\u6216\u8f6f\u4ef6\uff0c\u66f4\u662f\u6211\u4eec\u624b\u4e2d\u7684\u5229\u5668\uff0c\u6211\u4eec\u7684tools\u3002<br \/>shell\u662f\u6211\u4eec\u4e0e\u8ba1\u7b97\u673a\u4ea4\u4e92\u7684\u4e3b\u8981\u65b9\u5f0f\uff0c\u53ef\u89c6\u5316\u7684\u56fe\u5f62\u754c\u9762\u5176\u5b9e\u5f88\u53d7\u9650\uff0c\u4f60\u53ea\u80fd\u901a\u8fc7\u9884\u8bbe\u7684\u6309\u94ae\u53bb\u505a\u4e00\u4e9b\u4e8b\u60c5\u3002<\/p>\n<h4>2. Shell<\/h4>\n<h5>2.1 \u7a0b\u5e8f<\/h5>\n<p>\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u901a\u5e38\u90fd\u6709\u4e00\u4e2a\u201dshell\u201c\uff0c\u4f8b\u5982windows\u4e2d\u7684powershell\u3002\u5b83\u4eec\u4e4b\u95f4\u53ef\u80fd\u6709\u4e9b\u533a\u522b\uff0c\u4f46\u603b\u7684\u6765\u8bf4\u5dee\u4e0d\u591a\u3002\u5728windows\u7cfb\u7edf\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5b89\u88c5Git\uff0c\u4f7f\u7528linux\u98ce\u683c\u7684git bash \u3002\uff08windows \u4e0b\u7684git bash\u6709\u65f6\u4e5f\u4e0d\u592a\u4e00\u6837\uff0c\u66f4\u5efa\u8bae\u771f\u6b63\u7684linux\u7cfb\u7edf\uff09<\/p>\n<p>shell\u4e2d\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165\u7a0b\u5e8f\u540d\u6765\u6267\u884c\u7a0b\u5e8f\uff0c\u6bd4\u5982\u6709\u4e2a\u7a0b\u5e8f\u53ebdate\uff0c\u5c31\u4e4b\u95f4\u8f93\u5165\uff08$\u662f\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u5c31\u50cfwindows\u4e2d\u7684&gt;\uff09<\/p>\n<pre>$&nbsp;date\nSat&nbsp;Mar&nbsp;18&nbsp;20:52:33&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2023<\/pre>\n<p>\u53ef\u4ee5\u7ed9\u7a0b\u5e8f\u4f20\u9012\u53c2\u6570\uff0c\u4f8b\u5982\u7a0b\u5e8f<code>echo<\/code>\u7684\u8fd0\u884c\u6548\u679c\u5c31\u662f\u628a\u4f20\u9012\u7ed9\u5b83\u7684\u53c2\u6570\u6253\u5370\u51fa\u6765\uff0c<\/p>\n<pre>$&nbsp;echo&nbsp;hello\nhello<\/pre>\n<p>\u6b64\u5916\uff0c\u5982\u679c\u6709\u591a\u4e2a\u53c2\u6570\uff0c\u53c2\u6570\u4e4b\u95f4\u662f\u4f7f\u7528<strong>\u7a7a\u683c<\/strong>\u5206\u5f00\u7684\uff0c\u5982\u679c\u4f20\u591a\u5355\u8bcd\u7ec4\u6210\u7684\u53c2\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528<code>\\<\/code>(\u8f6c\u4e49\u5b57\u7b26\uff09\uff0c\u4f8b\u5982\u4e0b\u9762\u5176\u5b9e\u53ea\u7ed9<code>echo<\/code>\u4f20\u4e86\u4e00\u4e2a\u53c2\u6570\uff0c<\/p>\n<pre>$&nbsp;echo&nbsp;hello\\&nbsp;world\nhello&nbsp;world<\/pre>\n<p>\u7cfb\u7edf\u53ef\u4ee5\u627e\u5230\u4f60\u8f93\u5165\u7684\u7a0b\u5e8f\uff0c\u662f\u901a\u8fc7&nbsp;<strong>Path<\/strong>\uff08\u8def\u5f84\uff09\uff0c\u53ef\u4ee5\u67e5\u770b\u73af\u5883\u53d8\u91cf\u4e2d\u7684\u6240\u6709\u8def\u5f84<\/p>\n<pre>$&nbsp;echo&nbsp;$PATH\n\/c\/Users\/ThinkPad\/bin:\/mingw64\/bin:\/usr\/local\/bin:\/usr\/bin:\/bin:\/mingw64\/bin:\/usr\/bin:\/c\/Users\/ThinkPad\/bin:\/c\/Program&nbsp;Files\/Common&nbsp;\n...\uff08\u6211\u7701\u7565\u4e86\uff09<\/pre>\n<p>\u5728\u4f60\u8f93\u5165\u4e00\u4e2a\u7a0b\u5e8f\u540d\uff0c\u6bd4\u5982<code>echo<\/code>\u65f6\uff0cshell\u5c31\u4f1a\u5728\u7cfb\u7edf\u7684\u6240\u6709\u8def\u5f84\u7684\u76ee\u5f55\u4e2d\u641c\u7d22\u8be5\u7a0b\u5e8f\uff0c\u4f60\u53ef\u4ee5\u8fd9\u6837\u67e5\u770b\u4e00\u4e2a\u7a0b\u5e8f\u6240\u5728\u7684\u8def\u5f84<\/p>\n<pre>$&nbsp;which&nbsp;echo\n\/usr\/bin\/echo<\/pre>\n<p>\u8865\u5145\uff1a\u5173\u4e8e\u7a0b\u5e8f\uff08\u547d\u4ee4\uff09\u7684\u53c2\u6570\uff0c\u6211\u4eec\u4f7f\u7528<code>-<\/code>\u540e\u9762\u63a5\u5355\u4e2a\u5b57\u6bcd\uff0c\u4f7f\u7528<code>--<\/code>\u540e\u9762\u63a5\u5355\u8bcd\u3002\u4f8b\u5982<code>-a<\/code>\uff0c<code>--all<\/code>\u3002<\/p>\n<h4>2.2 \u76ee\u5f55<\/h4>\n<p>\u7a0b\u5e8f\u9ed8\u8ba4\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u8fd0\u884c\u3002\u4e0b\u9762\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u76ee\u5f55\u64cd\u4f5c<\/p>\n<table>\n<tbody>\n<tr>\n<th>\u547d\u4ee4<\/th>\n<th>\u4ecb\u7ecd<\/th>\n<\/tr>\n<tr>\n<td><code>pwd<\/code>(print work directory)<\/td>\n<td>\u6253\u5370\u5f53\u524d\u76ee\u5f55\u8def\u5f84<\/td>\n<\/tr>\n<tr>\n<td><code>ls<\/code><\/td>\n<td>\u5217\u51fa\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\uff0c\u4f7f\u7528<code>-l<\/code>\u53c2\u6570\u5c06\u663e\u793a\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td><code>cd<\/code><\/td>\n<td>\u5207\u6362\u76ee\u5f55\u5230\u6307\u5b9a\u76ee\u5f55\uff0c\u4f7f\u7528<code>cd -<\/code>\u53ef\u56de\u5230\u521a\u624d\u6240\u5728\u7684\u76ee\u5f55\uff0c\u65b9\u4fbf\u5728\u4e24\u4e2a\u76ee\u5f55\u95f4\u5207\u6362\u3002<code>.<\/code>\u8868\u793a\u5f53\u524d\u76ee\u5f55\uff0c<code>..<\/code>\u8868\u793a\u7236\u76ee\u5f55\uff0c<code>~<\/code>\u8868\u793a\u7528\u6237\u76ee\u5f55\uff0c<code>\/<\/code>\u5f00\u5934\u8868\u793a\u6839\u76ee\u5f55\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u901a\u8fc7<code>--help<\/code>\u53c2\u6570\uff0c\u53ef\u4ee5\u67e5\u770b\u67d0\u4e2a\u547d\u4ee4\u7684\u7528\u6cd5\uff0c\u4f8b\u5982<\/p>\n<pre>$&nbsp;ls&nbsp;--help<\/pre>\n<blockquote>\n<p><strong>\u60f3\u4e00\u60f3<\/strong>\uff1als -l\u5217\u51fa\u7684\u76ee\u5f55\u5217\u8868\u53ca\u5176\u4fe1\u606f\uff0c\u5982\u4f55\u89e3\u8bfb\uff1f<\/p>\n<\/blockquote>\n<p>\u800c\u64cd\u4f5c\u6587\u4ef6\u9700\u8981\u6743\u9650\uff0c\u4f60\u9700\u8981\u62e5\u6709\u6574\u6761\u8def\u5f84\u7684\u6743\u9650\u624d\u80fd\u5bf9\u6587\u4ef6\u8fdb\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002\u4e0b\u9762\u662f\u4e00\u4e9b\u548c\u6587\u4ef6\u64cd\u4f5c\u6709\u5173\u7684\u547d\u4ee4\u4ecb\u7ecd\u3002<\/p>\n<h4>2.3 \u6587\u4ef6<\/h4>\n<h5>2.3.1 \u7b80\u5355\u6587\u4ef6\u64cd\u4f5c<\/h5>\n<p>\u4f60\u53ef\u4ee5\u4f7f\u7528<code>mv<\/code>\u547d\u4ee4\u7ed9\u6587\u4ef6\u91cd\u547d\u540d\uff0c\u5373\u4f7f\u5b83\u662f<strong>move<\/strong>\uff08\u79fb\u52a8\uff09\u7684\u610f\u601d\u3002\u5047\u8bbe\u4f60\u5728\u5f53\u524d\u7684\u76ee\u5f55\u4e0b\u5df2\u7ecf\u6709\u4e2a\u6587\u4ef6<strong>hello.txt<\/strong>\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<\/p>\n<pre>$&nbsp;mv&nbsp;hello.txt&nbsp;hello2.txt<\/pre>\n<p>\u5c06\u5b83\u91cd\u547d\u540d\u4e3a<strong>hello2.txt<\/strong>\u3002<code>cp<\/code>\u547d\u4ee4\u53ef\u4ee5\u590d\u5236\u6587\u4ef6\uff0c\u5b83\u7684\u610f\u601d\u662f<strong>copy<\/strong>&nbsp;\uff08\u5f88\u663e\u7136\uff09\uff0c\u4f60\u53ef\u4ee5\u63a5\u7740\u521a\u624d\u7684\u547d\u4ee4\u4f7f\u7528<\/p>\n<pre>$&nbsp;cp&nbsp;hello2.txt&nbsp;hello.txt<\/pre>\n<p>\u90a3\u4e48\u4f60\u7684<strong>hello.txt<\/strong>\u6587\u4ef6\u53c8\u56de\u6765\u4e86\uff01\u73b0\u5728\u4f60\u6709\u4e86\u4e24\u4e2a\u76f8\u540c\u5185\u5bb9\u7684\u6587\u4ef6\uff0c\u5374\u6709\u7740\u4e0d\u4e00\u6837\u7684\u540d\u5b57\u3002\u4f46\u4f30\u8ba1\u4f60\u4f1a\u89c9\u5f97\u8fd9\u6709\u4e9b\u591a\u4f59\uff0c\u4f46\u597d\u5728\u4f60\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>rm<\/code>\u5220\u6389\u5176\u4e2d\u4e00\u4e2a\uff0c\u5c31\u50cf\u4e0b\u9762\u8fd9\u6837<\/p>\n<pre>$&nbsp;rm&nbsp;hello2.txt<\/pre>\n<p>\u597d\u4e86\uff0c\u73b0\u5728\u6211\u4eec\u53c8\u56de\u5230\u4e86\u521a\u521a\u5f00\u59cb\u7684\u6837\u5b50\uff0c\u4f46\u6211\u4eec\u521a\u521a\u7684\u64cd\u4f5c\u5df2\u7ecf\u5728\u7ec8\u7aef\u7559\u4e0b\u4e86\u6742\u4e71\u7684\u4fe1\u606f\uff0c\u4f7f\u7528<code>clear<\/code>\u547d\u4ee4\u6e05\u9664\u5b83\u4eec\uff01<\/p>\n<pre>$&nbsp;clear<\/pre>\n<p>\u5982\u679c\u4f60\u60f3\u65b0\u5efa\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>touch<\/code>\u547d\u4ee4\uff0c\u6bd4\u5982\u65b0\u5efa\u4e00\u4e2a\u7a7a<strong>hello2.txt<\/strong>\u6587\u4ef6<\/p>\n<pre>$&nbsp;touch&nbsp;hello2.txt<\/pre>\n<p>\u6709\u65f6\u4f60\u4f1a\u611f\u89c9\u547d\u4ee4\u7684\u540d\u5b57\u6709\u4e9b\u5947\u602a\uff0c\u4e3a\u4ec0\u4e48\u521b\u5efa\u6587\u4ef6\u8981\u662ftouch\uff1f\u5176\u5b9e\u5b83\u5c31\u50cf\u524d\u9762\u7684mv\u547d\u4ee4\uff0c\u91cd\u547d\u540d\u4ec5\u4ec5\u5bf9\u5b83\u7684\u4e00\u79cd\u4f7f\u7528\u65b9\u5f0f\uff0c\u800c\u5b83\u80fd\u505a\u7684\u4e0d\u6b62\u4e8e\u6b64\uff0c\u5b83\u5176\u5b9e\u53ef\u4ee5\u5c06\u6587\u4ef6\u79fb\u52a8\u5230\u4f60\u8ba1\u7b97\u673a\u7684\u4efb\u4f55\u4e00\u4e2a\u5730\u65b9\uff01<\/p>\n<p>touch\u662f\u4e00\u4e2a\u65f6\u95f4\u6233\u547d\u4ee4\uff0c\u5f53\u64cd\u4f5c\u7684\u6587\u4ef6\u4e0d\u5b58\u5728\u65f6\u5c31\u4f1a\u81ea\u52a8\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6&amp;mdash;&amp;mdash;\u800c\u4e0d\u662f\u5b83\u672c\u8eab\u53ea\u6709\u65b0\u5efa\u6587\u4ef6\u7684\u529f\u80fd\u3002\u5f53\u4f60\u611f\u5230\u7591\u60d1\u65f6\u53ef\u4ee5\u4f7f\u7528touch &#8211;help\u770b\u770b\u5e2e\u52a9\u6587\u6863\u3002\u800c\u6211\u4f7f\u7528echo\u547d\u4ee4\u540c\u6837\u8fbe\u5230\u65b0\u5efa\u6587\u4ef6\u7684\u76ee\u7684<\/p>\n<pre>$&nbsp;echo&nbsp;''&nbsp;&gt;&nbsp;hello3.txt<\/pre>\n<p>\u5b83\u5c06\u65b0\u5efa\u4e00\u4e2a\u7a7a\u6587\u4ef6<strong>hello3.txt<\/strong>&nbsp;\u3002\u4f60\u53ef\u80fd\u770b\u7740\u8fd9\u4e9blinux\u547d\u4ee4\u5c31\u50cf\u56de\u5230\u4e86\u9ad8\u4e2d\u80cc\u5355\u8bcd\u7684\u65f6\u5019\uff0c\u540c\u4e00\u4e2a\u5355\u8bcd\u6709\u7740\u76f8\u4e92\u7565\u5fae\u8054\u7cfb\u7684\u591a\u79cd\u7528\u6cd5&amp;mdash;&amp;mdash;\u4e5f\u786e\u5b9e\u5982\u6b64\uff0c\u5355\u8bcd\u662f\u8bed\u8a00\u7684\u57fa\u7840\u3002<\/p>\n<p>\u81f3\u4e8e\u521a\u521a\u547d\u4ee4\u4e2d\u7684<code>&gt;&gt;<\/code>\u7b26\u53f7\uff0c\u76f8\u4fe1\u5927\u5bb6\u4e00\u770b\u5c31\u61c2\uff0c\u6211\u4eec\u540e\u9762\u4e5f\u5c06\u4f1a\u8fdb\u4e00\u6b65\u4ecb\u7ecd\u3002<\/p>\n<h5>2.3.2 \u91cd\u5b9a\u5411<\/h5>\n<p>\u7a0b\u5e8f\u7684\u8f93\u51fa\u9664\u4e86\u76f4\u63a5\u663e\u793a\u5230\u5c4f\u5e55\u4e0a\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5c06\u5b83\u4fdd\u5b58\u5230\u6587\u4ef6\u91cc\uff0c\u800c\u91cd\u5b9a\u5411\u53ef\u4ee5\u5e2e\u4f60\u8fbe\u6210\u8fd9\u4e2a\u76ee\u6807\u3002\u8fd9\u91cc\u6709\u4e2a\u6d41\u7684\u6982\u5ff5\uff0c\u6bcf\u4e2a\u7a0b\u5e8f\u90fd\u6709\u81ea\u5df1\u7684\u8f93\u5165\u6d41\u4e0e\u8f93\u51fa\u6d41\uff0c\u7a0b\u5e8f\u4ece\u81ea\u5df1\u7684\u8f93\u5165\u6d41\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u5e76\u5c06\u8fd0\u884c\u7ed3\u679c\u5199\u5165\u5230\u8f93\u51fa\u6d41\u4e2d\u3002\u800c\u7a0b\u5e8f\u9ed8\u8ba4\u4ece\u952e\u76d8\u8f93\u5165\u83b7\u53d6\u6570\u636e\uff0c\u5e76\u5c06\u8fd0\u884c\u7ed3\u679c\u5199\u5230\u5c4f\u5e55\u4e0a\uff0c\u6211\u4eec\u5c06\u952e\u76d8\u8f93\u5165\u79f0\u4e3a\u6807\u51c6\u8f93\u5165\u6d41\uff0c\u5c06\u5c4f\u5e55\u79f0\u4e3a\u6807\u51c6\u8f93\u51fa\u6d41\u3002\u800c\u91cd\u5b9a\u5411\u5c06\u52a9\u4f60\u83b7\u5f97\u4fee\u6539\u7a0b\u5e8f\u8f93\u5165\u3001\u8f93\u51fa\u65b9\u5411\u7684\u80fd\u529b&amp;mdash;&amp;mdash;\u800c\u4e0d\u603b\u662f\u952e\u76d8\u548c\u5c4f\u5e55\u3002<\/p>\n<p><code>echo<\/code>\u547d\u4ee4\u5c06\u8f93\u5165\u6d41\u4e2d\u7684\u6570\u636e\u4f20\u9012\u5230\u8f93\u51fa\u6d41\uff0c\u4f46\u6211\u73b0\u5728\u4e0d\u60f3\u8f93\u51fa\u5230\u5c4f\u5e55\uff0c\u6211\u8981\u5c06\u8f93\u5165\u7684\u5185\u5bb9\u4fdd\u5b58\u5230\u6587\u4ef6\u91cc\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f7f\u7528<code>&gt;<\/code>&amp;mdash;&amp;mdash;\u91cd\u5b9a\u5411\u8f93\u51fa\u6d41\u3002<\/p>\n<pre>$&nbsp;echo&nbsp;hello&nbsp;&gt;&nbsp;hello.txt<\/pre>\n<blockquote>\n<p><strong>\u60f3\u4e00\u60f3<\/strong>\uff1a\u4e3a\u4ec0\u4e48<code>echo &lt; hello.txt<\/code>\u8f93\u51fa\u4e3a\u7a7a\uff1f<\/p>\n<\/blockquote>\n<p>\u7c7b\u4f3c\u5730\u53ef\u4ee5\u4f7f\u7528<code>&lt;<\/code>\u91cd\u5b9a\u5411\u8f93\u5165\u6d41\u3002<code>cat<\/code>\u547d\u4ee4\u53ef\u4ee5\u5c06\u6587\u4ef6\u8f93\u5165\u663e\u793a\u5230\u5c4f\u5e55\uff0c\u5982<\/p>\n<pre>$&nbsp;cat&nbsp;hello.txt\nhello<\/pre>\n<p>\u73b0\u5728\u6211\u4eec\u901a\u8fc7\u91cd\u5b9a\u5411\uff0c\u53ef\u4ee5\u5c06<strong>hello.txt<\/strong>\u6587\u4ef6\u7684\u5185\u5bb9\u590d\u5236\u5230\u53e6\u4e00\u4e2a\u6587\u4ef6<strong>hello2.txt<\/strong>\u4e2d<\/p>\n<pre>$&nbsp;cat&nbsp;&lt;&nbsp;hello.txt&nbsp;&gt;&nbsp;hello2.txt\n$&nbsp;cat&nbsp;hello2.txt\nhello<\/pre>\n<p><code>cat<\/code>\u7a0b\u5e8f\u4ece<strong>hello.txt<\/strong>\u4e2d\u83b7\u5f97\u8f93\u5165\uff0c\u5e76\u5c06\u8f93\u51fa\u5199\u5165\u4e86<strong>hello2.txt<\/strong>\u4e2d&amp;mdash;&amp;mdash;\u800c\u4e0d\u662f\u5c4f\u5e55\u4e0a\u3002<\/p>\n<p><code>&gt;<\/code>\u91cd\u5b9a\u5411\u7684\u8f93\u51fa\u6d41\u662f<strong>\u8986\u76d6\u6a21\u5f0f<\/strong>\uff0c\u5bf9\u5e94\u5230\u6587\u4ef6\u64cd\u4f5c\u4e2d\uff0c\u5c31\u662f\u5148\u6e05\u7a7a\u6587\u4ef6\u4e2d\u539f\u6709\u7684\u5185\u5bb9\uff0c\u7136\u540e\u5199\u5165\u65b0\u5185\u5bb9\u3002\u5982\u679c\u4f60\u662f\u60f3\u5728\u539f\u6765\u7684\u57fa\u7840\u4e0a\u6dfb\u52a0\u4e00\u4e9b\u5185\u5bb9\uff0c\u90a3\u4e48<code>&gt;&gt;<\/code>\u5f88\u9002\u5408\u4f60\uff0c\u5b83\u5c06\u4ee5<strong>\u8ffd\u52a0\u6a21\u5f0f<\/strong>\u5199\u5165\u65b0\u5185\u5bb9\u3002<\/p>\n<pre>$&nbsp;echo&nbsp;world&nbsp;&gt;&gt;&nbsp;hello.txt\n$&nbsp;cat&nbsp;hello.txt\nhello\nworld<\/pre>\n<table>\n<tbody>\n<tr>\n<th>\u547d\u4ee4<\/th>\n<th>\u4ecb\u7ecd<\/th>\n<\/tr>\n<tr>\n<td><code>&lt;<\/code><\/td>\n<td>\u91cd\u5b9a\u5411\u8f93\u5165\u6d41<\/td>\n<\/tr>\n<tr>\n<td><code>&gt;<\/code><\/td>\n<td>\u91cd\u5b9a\u5411\u8f93\u51fa\u6d41\uff0c\u4ee5\u8986\u76d6\u6a21\u5f0f\u5199\u5165<\/td>\n<\/tr>\n<tr>\n<td><code>&gt;&gt;<\/code><\/td>\n<td>\u91cd\u5b9a\u5411\u8f93\u51fa\u6d41\uff0c\u4ee5\u8ffd\u52a0\u6a21\u5f0f\u5199\u5165<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2.4 \u7ba1\u9053<\/h4>\n<p>\u4e00\u4e2a\u7a0b\u5e8f\u7684\u8f93\u51fa\u53ef\u4ee5\u4fdd\u5b58\u5230\u6587\u4ef6\u91cc\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4f20\u9012\u7ed9\u53e6\u4e00\u4e2a\u7a0b\u5e8f\u3002\u5c06\u5de6\u4fa7\u7a0b\u5e8f\u7684\u8f93\u51fa\u76f4\u63a5\u4f5c\u4e3a\u53f3\u4fa7\u7a0b\u5e8f\u7684\u8f93\u5165\uff0c\u8fd9\u4fbf\u662f\u7ba1\u9053\u7684\u4f5c\u7528\uff0c\u7ba1\u9053\u7b26\u4e3a|\u3002<\/p>\n<p>tail\u547d\u4ee4\u901a\u8fc7-n\u53c2\u6570\uff0c\u53ef\u4ee5\u8f93\u51fa\u5b83\u8f93\u5165\u4e2d\u7684\u6700\u540en\u884c\u3002\u547d\u4ee4ls -l \/\u4f1a\u663e\u793a\u51fa\u5f88\u591a\u4fe1\u606f\uff0c\u90a3\u4e48\u901a\u8fc7\u4e0b\u9762\u7684\u547d\u4ee4\u6211\u53ef\u4ee5\u53ea\u663e\u793a\u5176\u4e2d\u6700\u540e\u4e24\u884c\uff1a<\/p>\n<pre>$&nbsp;ls&nbsp;-l&nbsp;\/&nbsp;|&nbsp;tail&nbsp;-n&nbsp;2\n-rw-r--r--&nbsp;&nbsp;1&nbsp;ThinkPad&nbsp;197121&nbsp;&nbsp;&nbsp;24183&nbsp;Nov&nbsp;28&nbsp;12:20&nbsp;unins000.msg\ndrwxr-xr-x&nbsp;&nbsp;1&nbsp;ThinkPad&nbsp;197121&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;Nov&nbsp;28&nbsp;12:20&nbsp;usr\/<\/pre>\n<p><code>tee<\/code>\u547d\u4ee4\u53ef\u4ee5\u5c06\u8f93\u5165\u540c\u65f6\u8f93\u51fa\u5230\u5c4f\u5e55\u548c\u6307\u5b9a\u7684\u6587\u4ef6\u4e2d\uff0c\u90a3\u4e48\u52a0\u4e0a\u7ba1\u9053\u4f60\u53ef\u4ee5\u50cf\u4e0b\u9762\u8fd9\u6837<\/p>\n<pre>$&nbsp;echo&nbsp;linux1234&nbsp;|&nbsp;tee&nbsp;hello.txt\nlinux1234<\/pre>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aLinux&nbsp;Shell\u7684\u5e38\u7528\u64cd\u4f5c\u6709\u54ea\u4e9b\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux&nbsp;Shell\u7684\u5e38\u7528\u64cd\u4f5c\u6709\u54ea\u4e9b \u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aLinux&nbsp;Shell\u7684\u5e38\u7528\u64cd\u4f5c\u6709\u54ea\u4e9b\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b Linux\u30111 Shell 1. \u8bed\u5f55 \u8ba1\u7b97\u673a\u4e0d\u4ec5\u4ec5\u7528\u6765\u5f00\u53d1\u4e2a\u7f51\u7ad9\u6216\u8f6f\u4ef6\uff0c\u66f4\u662f\u6211\u4eec\u624b\u4e2d\u7684\u5229\u5668\uff0c\u6211\u4eec\u7684tools\u3002shell\u662f\u6211\u4eec\u4e0e\u8ba1\u7b97\u673a\u4ea4\u4e92\u7684\u4e3b\u8981\u65b9\u5f0f\uff0c\u53ef\u89c6\u5316\u7684\u56fe\u5f62\u754c\u9762\u5176\u5b9e\u5f88\u53d7\u9650\uff0c\u4f60\u53ea\u80fd\u901a\u8fc7\u9884\u8bbe\u7684\u6309\u94ae\u53bb\u505a\u4e00\u4e9b\u4e8b\u60c5\u3002 2. Shell 2.1 \u7a0b\u5e8f \u64cd\u4f5c\u7cfb\u7edf\u4e2d\u901a\u5e38\u90fd\u6709\u4e00\u4e2a\u201dshell\u201c\uff0c\u4f8b\u5982windows\u4e2d\u7684powershell\u3002\u5b83\u4eec\u4e4b\u95f4\u53ef\u80fd\u6709\u4e9b\u533a\u522b\uff0c\u4f46\u603b\u7684\u6765\u8bf4\u5dee\u4e0d\u591a\u3002\u5728windows\u7cfb\u7edf\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5b89\u88c5Git\uff0c\u4f7f\u7528linux\u98ce\u683c\u7684git bash \u3002\uff08windows \u4e0b\u7684git bash\u6709\u65f6\u4e5f\u4e0d\u592a\u4e00\u6837\uff0c\u66f4\u5efa\u8bae\u771f\u6b63\u7684linux\u7cfb\u7edf\uff09 shell\u4e2d\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165\u7a0b\u5e8f\u540d\u6765\u6267\u884c\u7a0b\u5e8f\uff0c\u6bd4\u5982\u6709\u4e2a\u7a0b\u5e8f\u53ebdate\uff0c\u5c31\u4e4b\u95f4\u8f93\u5165\uff08$\u662f\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u5c31\u50cfwindows\u4e2d\u7684&gt;\uff09 $&nbsp;date Sat&nbsp;Mar&nbsp;18&nbsp;20:52:33&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2023 \u53ef\u4ee5\u7ed9\u7a0b\u5e8f\u4f20\u9012\u53c2\u6570\uff0c\u4f8b\u5982\u7a0b\u5e8fecho\u7684\u8fd0\u884c\u6548\u679c\u5c31\u662f\u628a\u4f20\u9012\u7ed9\u5b83\u7684\u53c2\u6570\u6253\u5370\u51fa\u6765\uff0c $&nbsp;echo&nbsp;hello hello \u6b64\u5916\uff0c\u5982\u679c\u6709\u591a\u4e2a\u53c2\u6570\uff0c\u53c2\u6570\u4e4b\u95f4\u662f\u4f7f\u7528\u7a7a\u683c\u5206\u5f00\u7684\uff0c\u5982\u679c\u4f20\u591a\u5355\u8bcd\u7ec4\u6210\u7684\u53c2\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\\(\u8f6c\u4e49\u5b57\u7b26\uff09\uff0c\u4f8b\u5982\u4e0b\u9762\u5176\u5b9e\u53ea\u7ed9echo\u4f20\u4e86\u4e00\u4e2a\u53c2\u6570\uff0c $&nbsp;echo&nbsp;hello\\&nbsp;world hello&nbsp;world \u7cfb\u7edf\u53ef\u4ee5\u627e\u5230\u4f60\u8f93\u5165\u7684\u7a0b\u5e8f\uff0c\u662f\u901a\u8fc7&nbsp;Path\uff08\u8def\u5f84\uff09\uff0c\u53ef\u4ee5\u67e5\u770b\u73af\u5883\u53d8\u91cf\u4e2d\u7684\u6240\u6709\u8def\u5f84 $&nbsp;echo&nbsp;$PATH \/c\/Users\/ThinkPad\/bin:\/mingw64\/bin:\/usr\/local\/bin:\/usr\/bin:\/bin:\/mingw64\/bin:\/usr\/bin:\/c\/Users\/ThinkPad\/bin:\/c\/Program&nbsp;Files\/Common&nbsp; &#8230;\uff08\u6211\u7701\u7565\u4e86\uff09 \u5728\u4f60\u8f93\u5165\u4e00\u4e2a\u7a0b\u5e8f\u540d\uff0c\u6bd4\u5982echo\u65f6\uff0cshell\u5c31\u4f1a\u5728\u7cfb\u7edf\u7684\u6240\u6709\u8def\u5f84\u7684\u76ee\u5f55\u4e2d\u641c\u7d22\u8be5\u7a0b\u5e8f\uff0c\u4f60\u53ef\u4ee5\u8fd9\u6837\u67e5\u770b\u4e00\u4e2a\u7a0b\u5e8f\u6240\u5728\u7684\u8def\u5f84 $&nbsp;which&nbsp;echo \/usr\/bin\/echo \u8865\u5145\uff1a\u5173\u4e8e\u7a0b\u5e8f\uff08\u547d\u4ee4\uff09\u7684\u53c2\u6570\uff0c\u6211\u4eec\u4f7f\u7528-\u540e\u9762\u63a5\u5355\u4e2a\u5b57\u6bcd\uff0c\u4f7f\u7528&#8211;\u540e\u9762\u63a5\u5355\u8bcd\u3002\u4f8b\u5982-a\uff0c&#8211;all\u3002 2.2 \u76ee\u5f55 \u7a0b\u5e8f\u9ed8\u8ba4\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u8fd0\u884c\u3002\u4e0b\u9762\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u76ee\u5f55\u64cd\u4f5c \u547d\u4ee4 \u4ecb\u7ecd pwd(print work directory) \u6253\u5370\u5f53\u524d\u76ee\u5f55\u8def\u5f84 ls \u5217\u51fa\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\uff0c\u4f7f\u7528-l\u53c2\u6570\u5c06\u663e\u793a\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f cd \u5207\u6362\u76ee\u5f55\u5230\u6307\u5b9a\u76ee\u5f55\uff0c\u4f7f\u7528cd -\u53ef\u56de\u5230\u521a\u624d\u6240\u5728\u7684\u76ee\u5f55\uff0c\u65b9\u4fbf\u5728\u4e24\u4e2a\u76ee\u5f55\u95f4\u5207\u6362\u3002.\u8868\u793a\u5f53\u524d\u76ee\u5f55\uff0c..\u8868\u793a\u7236\u76ee\u5f55\uff0c~\u8868\u793a\u7528\u6237\u76ee\u5f55\uff0c\/\u5f00\u5934\u8868\u793a\u6839\u76ee\u5f55\u3002 \u901a\u8fc7&#8211;help\u53c2\u6570\uff0c\u53ef\u4ee5\u67e5\u770b\u67d0\u4e2a\u547d\u4ee4\u7684\u7528\u6cd5\uff0c\u4f8b\u5982 $&nbsp;ls&nbsp;&#8211;help \u60f3\u4e00\u60f3\uff1als -l\u5217\u51fa\u7684\u76ee\u5f55\u5217\u8868\u53ca\u5176\u4fe1\u606f\uff0c\u5982\u4f55\u89e3\u8bfb\uff1f \u800c\u64cd\u4f5c\u6587\u4ef6\u9700\u8981\u6743\u9650\uff0c\u4f60\u9700\u8981\u62e5\u6709\u6574\u6761\u8def\u5f84\u7684\u6743\u9650\u624d\u80fd\u5bf9\u6587\u4ef6\u8fdb\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002\u4e0b\u9762\u662f\u4e00\u4e9b\u548c\u6587\u4ef6\u64cd\u4f5c\u6709\u5173\u7684\u547d\u4ee4\u4ecb\u7ecd\u3002 2.3 \u6587\u4ef6 2.3.1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-51968","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/51968","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=51968"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/51968\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=51968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=51968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=51968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}