{"id":115493,"date":"2026-10-12T08:57:43","date_gmt":"2026-10-12T00:57:43","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/115493.html"},"modified":"2026-10-12T08:57:43","modified_gmt":"2026-10-12T00:57:43","slug":"%e3%80%90linux%e7%b3%bb%e7%bb%9f%e3%80%91%e3%80%90cd%e5%a4%b1%e6%95%88%e8%83%8c%e5%90%8e%e7%9a%84%e8%bf%9b%e7%a8%8b%e7%9c%9f%e7%9b%b8%ef%bc%9a%e5%86%85%e5%bb%ba%e5%91%bd%e4%bb%a4%e7%9a%84%e6%ad%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/115493.html","title":{"rendered":"\u3010Linux\u7cfb\u7edf\u3011\u3010cd\u5931\u6548\u80cc\u540e\u7684\u8fdb\u7a0b\u771f\u76f8\uff1a\u5185\u5efa\u547d\u4ee4\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f\u3011\u6d41\u98df\u822c\u6295\u5582"},"content":{"rendered":"<h2>\u5f53 cd \u7a81\u7136\u5931\u6548&#xff1a;\u4e00\u6b21\u81ea\u5b9a\u4e49 Shell \u7684\u5185\u5efa\u547d\u4ee4\u6df1\u5ea6\u7a81\u56f4<\/h2>\n<p>\u201c\u6211\u4eec\u5199\u4e86 120 \u884c\u4ee3\u7801&#xff0c;\u4ee5\u4e3a\u81ea\u5df1\u62e5\u6709\u4e86\u4e00\u4e2a Shell&#xff1b;\u76f4\u5230\u8f93\u5165 cd .. \u5374\u53d1\u73b0\u7eb9\u4e1d\u4e0d\u52a8&#xff0c;\u624d\u610f\u8bc6\u5230\u2014\u2014\u539f\u6765\u6211\u4eec\u53ea\u662f\u5728\u548c\u5b50\u8fdb\u7a0b\u2019\u73a9\u8fc7\u5bb6\u5bb6\u2019\u3002\u201d<\/p>\n<p>\u8fd9\u662f\u8bfe\u5802\u4e0a\u8001\u5e08\u629b\u51fa\u7684\u4e00\u4e2a\u7ecf\u5178\u573a\u666f\u3002\u4e0a\u8282\u8bfe&#xff0c;\u6211\u4eec\u5b8c\u6210\u4e86\u81ea\u5b9a\u4e49 Shell&#xff08;myshell&#xff09;\u7684\u57fa\u7840\u6846\u67b6&#xff0c;\u5927\u7ea6 120 \u884c\u4ee3\u7801&#xff0c;\u5b9e\u73b0\u4e86\u83b7\u53d6\u7528\u6237\u540d\u3001\u4e3b\u673a\u540d\u3001\u5f53\u524d\u8def\u5f84\u3001\u547d\u4ee4\u884c\u89e3\u6790\u548c\u57fa\u672c\u547d\u4ee4\u6267\u884c\u3002\u4e00\u5207\u770b\u8d77\u6765\u90fd\u5f88\u7f8e\u597d&#xff1a;ls\u3001pwd \u90fd\u80fd\u6b63\u5e38\u5de5\u4f5c\u3002\u4f46\u504f\u504f\u6700\u5e38\u7528\u7684 cd ..&#xff0c;\u8fd8\u6709 export&#xff08;\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf&#xff0c;export\u547d\u4ee4\u7528\u4e8e\u5c06\u53d8\u91cf\u5bfc\u51fa\u4e3a\u73af\u5883\u53d8\u91cf&#xff0c;\u4f7f\u5176\u5728\u5f53\u524dshell\u4f1a\u8bdd\u53ca\u5176\u5b50\u8fdb\u7a0b\u4e2d\u53ef\u7528\u3002\u901a\u8fc7\u8be5\u547d\u4ee4\u5b9a\u4e49\u7684\u53d8\u91cf\u4f1a\u6210\u4e3a\u5168\u5c40\u73af\u5883\u53d8\u91cf&#xff0c;\u5f71\u54cd\u540e\u7eed\u8fd0\u884c\u7684\u7a0b\u5e8f\u548c\u811a\u672c\u3002&#xff09;&#xff0c;\u6210\u4e86&#034;\u9489\u5b50\u6237&#034;\u2014\u2014\u5b83\u4eec\u4f3c\u4e4e\u5b8c\u5168\u65e0\u89c6\u6211\u4eec\u7684\u6307\u4ee4\u3002<\/p>\n<p>\u672c\u7ae0\u8282\u7684\u6838\u5fc3&#xff0c;\u5c31\u662f\u89e3\u51b3\u8fd9\u4e2a&#034;\u8def\u5f84\u5207\u6362\u5931\u6548&#034;\u7684\u75db\u70b9&#xff0c;\u5e76\u4ee5\u6b64\u4e3a\u5951\u673a&#xff0c;\u6df1\u5165\u7406\u89e3\u8fdb\u7a0b\u4e0e\u6587\u4ef6\u7684\u5173\u7cfb\u3002\u5982\u679c\u4f60\u4e5f\u6b63\u5728\u624b\u5199 Shell \u6216\u8005\u5bf9 Linux \u7cfb\u7edf\u7f16\u7a0b\u611f\u5174\u8da3&#xff0c;\u8fd9\u7bc7\u6587\u7ae0\u5c06\u5e2e\u4f60\u7406\u6e05\u90a3\u4e9b&#034;\u770b\u4f3c\u7b80\u5355&#xff0c;\u5b9e\u5219\u6697\u85cf\u7384\u673a&#034;\u7684\u673a\u5236\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u6838\u5fc3\u673a\u5236&#xff1a;\u4e3a\u4ec0\u4e48 cd \u5fc5\u987b\u7531\u7236\u8fdb\u7a0b\u4eb2\u81ea\u6267\u884c&#xff1f;<\/h3>\n<h4>1.1 \u4ee4\u4eba\u56f0\u60d1\u7684\u73b0\u8c61<\/h4>\n<p>\u5f53\u6211\u4eec\u5728\u81ea\u5b9a\u4e49 Shell \u4e2d\u6267\u884c&#xff1a;<\/p>\n<p><span class=\"token builtin class-name\">cd<\/span> <span class=\"token punctuation\">..<\/span><br \/>\n<span class=\"token builtin class-name\">pwd<\/span><\/p>\n<p>\u53d1\u73b0\u5f53\u524d\u8def\u5f84\u5e76\u672a\u771f\u6b63\u6539\u53d8\u3002\u8fd9\u662f\u521d\u5b66\u8005\u6700\u5e38\u89c1\u7684\u632b\u8d25\u4e4b\u4e00\u3002\u6211\u4eec\u660e\u660e\u8c03\u7528\u4e86\u7cfb\u7edf\u547d\u4ee4&#xff0c;\u4e3a\u4ec0\u4e48\u8def\u5f84\u7eb9\u4e1d\u4e0d\u52a8&#xff1f;<\/p>\n<h4>1.2 \u672c\u8d28\u539f\u56e0&#xff1a;\u8fdb\u7a0b\u7684\u72ec\u7acb\u6027<\/h4>\n<p>\u8001\u5e08\u8bfe\u4e0a\u7684\u4e00\u53e5\u8bdd\u70b9\u7834\u4e86\u771f\u76f8&#xff1a;<\/p>\n<p>\u201c\u666e\u901a\u547d\u4ee4\u901a\u8fc7 fork \u521b\u5efa\u5b50\u8fdb\u7a0b\u6267\u884c&#xff0c;\u5b50\u8fdb\u7a0b\u62e5\u6709\u72ec\u7acb\u7684\u8fdb\u7a0b\u63a7\u5236\u5757&#xff08;PCB&#xff09;&#xff0c;\u5176\u4e2d\u7ef4\u62a4\u4e86\u5404\u81ea\u7684\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55&#xff08;CWD&#xff09;\u3002\u201d<\/p>\n<p>\u6362\u53e5\u8bdd\u8bf4&#xff1a;<\/p>\n<ul>\n<li>\u5b50\u8fdb\u7a0b\u4fee\u6539\u7684\u662f\u81ea\u5df1\u7684 CWD&#xff1b;<\/li>\n<li>\u5b50\u8fdb\u7a0b\u7ed3\u675f\u540e&#xff0c;\u5b83\u7684\u6240\u6709\u72b6\u6001\u90fd\u88ab\u56de\u6536&#xff1b;<\/li>\n<li>\u7236\u8fdb\u7a0b&#xff08;\u4e5f\u5c31\u662f\u6211\u4eec\u7684 Shell \u672c\u4f53&#xff09;\u7684 CWD \u6beb\u53d1\u65e0\u635f\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u5c31\u50cf\u4f60\u8ba9\u4e00\u4e2a\u66ff\u8eab\u53bb\u5e2e\u4f60\u642c\u5bb6&#xff0c;\u66ff\u8eab\u786e\u5b9e\u642c\u5230\u4e86\u65b0\u5bb6&#xff0c;\u4f46\u4f60\u81ea\u5df1\u8fd8\u5750\u5728\u539f\u5904\u3002\u56e0\u6b64&#xff0c;cd\u3001export \u8fd9\u7c7b\u547d\u4ee4\u5fc5\u987b\u7531 Shell \u7236\u8fdb\u7a0b\u4eb2\u81ea\u6267\u884c&#xff0c;\u624d\u80fd\u771f\u6b63\u6539\u53d8\u5f53\u524d\u4f1a\u8bdd\u7684\u73af\u5883\u72b6\u6001\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u67b6\u6784\u4f18\u5316&#xff1a;\u5185\u5efa\u547d\u4ee4\u68c0\u6d4b\u6d41\u7a0b<\/h3>\n<p>\u89e3\u51b3\u65b9\u6848\u4e0d\u662f\u76f2\u76ee\u4fee\u6539&#xff0c;\u800c\u662f\u5728\u6267\u884c\u5916\u90e8\u547d\u4ee4&#xff08;exec&#xff09;\u4e4b\u524d&#xff0c;\u589e\u52a0\u4e00\u6b65**\u201c\u5185\u5efa\u547d\u4ee4\u68c0\u6d4b\u201d**\u73af\u8282\u3002\u8bfe\u4e0a\u8001\u5e08\u5c06\u8fd9\u4e2a\u6d41\u7a0b\u68b3\u7406\u4e3a\u4e09\u6b65&#xff1a;<\/p>\n<h4>2.1 \u7b2c\u4e00\u6b65&#xff1a;\u89e3\u6790\u6821\u9a8c&#xff08;\u5065\u58ee\u6027\u589e\u5f3a&#xff09;<\/h4>\n<p>\u5728\u89e3\u6790\u547d\u4ee4\u884c\u65f6&#xff0c;\u5fc5\u987b\u68c0\u67e5\u53c2\u6570\u4e2a\u6570 argc\u3002\u8001\u5e08\u7279\u522b\u5f3a\u8c03\u4e86\u4e00\u4e2a\u8fb9\u754c\u60c5\u51b5&#xff1a;<\/p>\n<p>\u201c\u82e5 argc &lt;&#061; 0&#xff08;\u5982\u7528\u6237\u4ec5\u6309\u56de\u8f66&#xff09;&#xff0c;\u5e94\u89c6\u4e3a\u89e3\u6790\u5931\u8d25\u6216\u65e0\u64cd\u4f5c&#xff0c;\u76f4\u63a5\u8df3\u8fc7\u540e\u7eed\u6267\u884c\u6b65\u9aa4&#xff0c;\u907f\u514d\u9519\u8bef\u8fdb\u5165\u6267\u884c\u903b\u8f91\u3002\u201d<\/p>\n<p>\u89e3\u6790\u51fd\u6570\u8fd4\u56de\u5e03\u5c14\u503c&#xff1a;<\/p>\n<ul>\n<li>\u6210\u529f&#xff08;argc &gt; 0&#xff09;&#xff1a;\u7ee7\u7eed\u6267\u884c&#xff1b;<\/li>\n<li>\u5931\u8d25&#xff08;argc &lt;&#061; 0&#xff09;&#xff1a;continue&#xff0c;\u8fdb\u5165\u4e0b\u4e00\u8f6e\u5faa\u73af\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e00\u6b65\u867d\u7136\u7ec6\u5c0f&#xff0c;\u5374\u662f\u4ee3\u7801\u5065\u58ee\u6027\u7684\u91cd\u8981\u4fdd\u969c\u3002<\/p>\n<h4>2.2 \u7b2c\u4e8c\u6b65&#xff1a;\u5185\u7f6e\u68c0\u6d4b&#xff08;check_builtin&#xff09;<\/h4>\n<p>\u8001\u5e08\u8bbe\u8ba1\u4e86\u4e00\u4e2a\u6781\u7b80\u63a5\u53e3&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ \u65e0\u9700\u989d\u5916\u4f20\u53c2&#xff0c;\u76f4\u63a5\u8bbf\u95ee\u5168\u5c40\u89e3\u6790\u597d\u7684 argv \u6570\u7ec4<\/span><br \/>\n<span class=\"token comment\">\/\/ \u8fd4\u56de bool&#xff1a;true \u8868\u793a\u662f\u5185\u5efa\u547d\u4ee4\u4e14\u5df2\u5904\u7406&#xff0c;false \u8868\u793a\u975e\u5185\u5efa\u547d\u4ee4<\/span><br \/>\n<span class=\"token keyword\">bool<\/span> <span class=\"token function\">check_builtin<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5224\u65ad\u903b\u8f91\u975e\u5e38\u76f4\u63a5&#xff1a;\u63d0\u53d6 cmd &#061; argv[0]&#xff08;\u83b7\u53d6\u547d\u4ee4\u884c\u53c2\u6570\u4e2d\u7684\u7a0b\u5e8f\u8def\u5f84&#xff09;&#xff0c;\u4f7f\u7528\u5b57\u7b26\u4e32\u6bd4\u8f83\u5224\u65ad\u662f\u5426\u4e3a &#034;cd&#034;\u3001&#034;echo&#034;\u3001&#034;export&#034; \u7b49\u7279\u5b9a\u547d\u4ee4\u3002<\/p>\n<h4>2.3 \u7b2c\u4e09\u6b65&#xff1a;\u5206\u652f\u6267\u884c<\/h4>\n<ul>\n<li>\u82e5\u662f\u5185\u5efa\u547d\u4ee4&#xff1a;\u7531\u7236\u8fdb\u7a0b\u76f4\u63a5\u8c03\u7528\u5904\u7406\u51fd\u6570&#xff0c;\u7ed5\u8fc7 fork\/exec&#xff1b;<\/li>\n<li>\u82e5\u4e0d\u662f\u5185\u5efa\u547d\u4ee4&#xff1a;\u7ee7\u7eed\u5e38\u89c4\u7684 fork\/exec \u6d41\u7a0b&#xff0c;\u521b\u5efa\u5b50\u8fdb\u7a0b\u6267\u884c\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e09\u3001\u4ee3\u7801\u5b9e\u73b0&#xff1a;cd \u547d\u4ee4\u4e0e chdir \u8c03\u7528<\/h3>\n<h4>3.1 \u6838\u5fc3\u7cfb\u7edf\u8c03\u7528&#xff1a;chdir<\/h4>\n<p>\u7236\u8fdb\u7a0b\u5982\u4f55\u771f\u6b63\u5207\u6362\u8def\u5f84&#xff1f;\u7b54\u6848\u662f chdir&#xff1a;<br \/>\n&#x1f4cc;chdir&#xff08;\u5728 Shell \u811a\u672c\u4e2d&#xff0c;cd \u547d\u4ee4\u672c\u8d28\u4e0a\u662f\u8c03\u7528 chdir \u7cfb\u7edf\u8c03\u7528&#xff0c;\u5176\u6838\u5fc3\u529f\u80fd\u662f\u5c06\u7a0b\u5e8f\u6216\u7ec8\u7aef\u7684\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u5207\u6362\u5230\u6307\u5b9a\u8def\u5f84&#xff0c;\u4ece\u800c\u5f71\u54cd\u540e\u7eed\u6587\u4ef6\u64cd\u4f5c\u3001\u8def\u5f84\u89e3\u6790\u548c\u8d44\u6e90\u8bbf\u95ee\u7684\u884c\u4e3a\u3002&#xff09;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;unistd.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">chdir<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> <span class=\"token keyword\">char<\/span> <span class=\"token operator\">*<\/span>path<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8001\u5e08\u8bfe\u4e0a\u53cd\u590d\u5f3a\u8c03&#xff1a;\u201c\u54ea\u4e2a\u8fdb\u7a0b\u8c03\u7528 chdir&#xff0c;\u5c31\u66f4\u6539\u54ea\u4e2a\u8fdb\u7a0b\u7684\u5de5\u4f5c\u8def\u5f84\u3002\u201d \u6b63\u56e0\u5982\u6b64&#xff0c;\u6211\u4eec\u5fc5\u987b\u786e\u4fdd\u8c03\u7528 chdir \u7684\u662f Shell \u7236\u8fdb\u7a0b\u672c\u8eab&#xff0c;\u800c\u4e0d\u662f\u5b50\u8fdb\u7a0b\u3002<\/p>\n<h4>3.2 \u8def\u5f84\u5904\u7406\u903b\u8f91<\/h4>\n<p>cd \u547d\u4ee4\u7684\u5b9e\u73b0\u4e2d\u5305\u542b\u51e0\u4e2a\u5178\u578b\u573a\u666f&#xff1a;<\/p>\n<p>\u9ed8\u8ba4\u884c\u4e3a&#xff08;\u65e0\u53c2\u6570&#xff09;&#xff1a;<br \/>\n\u5982\u679c\u7528\u6237\u76f4\u63a5\u8f93\u5165 cd \u56de\u8f66&#xff0c;\u9ed8\u8ba4\u5e94\u8fdb\u5165\u7528\u6237\u5bb6\u76ee\u5f55\u3002\u901a\u8fc7 getenv(&#034;HOME&#034;) \u83b7\u53d6\u5bb6\u76ee\u5f55\u8def\u5f84&#xff1a;<\/p>\n<p><span class=\"token keyword\">const<\/span> <span class=\"token keyword\">char<\/span><span class=\"token operator\">*<\/span> home <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">getenv<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;HOME&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>home<span class=\"token punctuation\">)<\/span> <span class=\"token function\">chdir<\/span><span class=\"token punctuation\">(<\/span>home<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u7279\u6b8a\u7b26\u53f7&#xff08;\u5f85\u5b8c\u5584&#xff09;&#xff1a;<\/p>\n<ul>\n<li>cd ~&#xff1a;\u6620\u5c04\u5230\u5bb6\u76ee\u5f55&#xff1b;<\/li>\n<li>cd -&#xff1a;\u6620\u5c04\u5230\u4e0a\u4e00\u4e2a\u5de5\u4f5c\u76ee\u5f55&#xff08;\u8bfe\u4e0a\u63d0\u53ca\u4f46\u672a\u5c55\u5f00\u5177\u4f53\u5b9e\u73b0&#xff0c;\u9700\u8981\u8bb0\u5f55\u5386\u53f2\u8def\u5f84&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u76f8\u5bf9\/\u7edd\u5bf9\u8def\u5f84&#xff1a;<br \/>\n\u76f4\u63a5\u4f20\u5165 chdir \u5373\u53ef&#xff0c;\u7cfb\u7edf\u4f1a\u81ea\u52a8\u5904\u7406\u3002<\/p>\n<h4>3.3 \u9690\u85cf\u9677\u9631&#xff1a;PWD \u73af\u5883\u53d8\u91cf\u7684\u540c\u6b65<\/h4>\n<p>\u5f53\u4f60\u7ec8\u4e8e\u7528 chdir \u5207\u6362\u4e86\u76ee\u5f55&#xff0c;\u4f1a\u53d1\u73b0\u63d0\u793a\u7b26\u663e\u793a\u7684\u8def\u5f84\u4f9d\u7136\u6ca1\u53d8&#xff01;\u8fd9\u662f\u4e3a\u4ec0\u4e48&#xff1f;<\/p>\n<p>\u8001\u5e08\u63ed\u793a\u4e86\u4e00\u4e2a\u5173\u952e\u7ec6\u8282&#xff1a;<\/p>\n<p>\u201c\u8fdb\u7a0b\u5de5\u4f5c\u8def\u5f84\u6539\u53d8\u540e&#xff0c;\u64cd\u4f5c\u7cfb\u7edf\u4e0d\u4f1a\u81ea\u52a8\u66f4\u65b0 Shell \u7684 PWD \u73af\u5883\u53d8\u91cf\u3002\u73af\u5883\u53d8\u91cf\u7684\u66f4\u65b0\u5de5\u4f5c\u901a\u5e38\u9700\u8981\u81ea\u5df1\u5b8c\u6210\u3002\u201d<\/p>\n<p>\u5982\u679c\u63d0\u793a\u7b26\u662f\u901a\u8fc7\u8bfb\u53d6 $PWD \u73af\u5883\u53d8\u91cf\u6765\u663e\u793a\u8def\u5f84\u7684&#xff0c;\u90a3\u4e48 chdir \u4e4b\u540e&#xff0c;\u4f60\u5fc5\u987b\u624b\u52a8\u540c\u6b65&#xff1a;<\/p>\n<li>\u4f7f\u7528 getcwd() \u83b7\u53d6\u771f\u5b9e\u7684\u5f53\u524d\u5de5\u4f5c\u8def\u5f84&#xff08;\u800c\u975e\u4f9d\u8d56\u53ef\u80fd\u6ede\u540e\u7684 PWD&#xff09;&#xff1b;<\/li>\n<li>\u4f7f\u7528 putenv() \u5c06\u65b0\u7684 PWD&#061;\u8def\u5f84 \u5199\u5165\u8fdb\u7a0b\u73af\u5883\u53d8\u91cf\u7a7a\u95f4\u3002<\/li>\n<p><span class=\"token keyword\">char<\/span> cwd<span class=\"token punctuation\">[<\/span><span class=\"token number\">1024<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">getcwd<\/span><span class=\"token punctuation\">(<\/span>cwd<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>cwd<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">char<\/span> env_pwd<span class=\"token punctuation\">[<\/span><span class=\"token number\">1024<\/span> <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">4<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">snprintf<\/span><span class=\"token punctuation\">(<\/span>env_pwd<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>env_pwd<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;PWD&#061;%s&#034;<\/span><span class=\"token punctuation\">,<\/span> cwd<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">putenv<\/span><span class=\"token punctuation\">(<\/span>env_pwd<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u5bfc\u51fa\u5230\u8fdb\u7a0b\u4e0a\u4e0b\u6587<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8bfe\u4e0a\u8001\u5e08\u751a\u81f3\u4e3a\u6b64\u4e13\u95e8\u4fee\u6b63\u4e86\u4e4b\u524d\u7684\u4ee3\u7801&#xff1a;\u201c\u4f60\u5e94\u8be5\u4f18\u5148\u901a\u8fc7 getcwd \u83b7\u53d6\u771f\u5b9e\u8def\u5f84&#xff0c;\u518d\u540c\u6b65\u66f4\u65b0\u73af\u5883\u53d8\u91cf\u3002\u201d \u8fd9\u786e\u4fdd\u540e\u7eed\u547d\u4ee4\u83b7\u53d6\u7684\u8def\u5f84\u59cb\u7ec8\u6b63\u786e\u3002<\/p>\n<hr \/>\n<h3>\u56db\u3001\u6269\u5c55&#xff1a;\u4ece cd \u5230 echo \u4e0e\u73af\u5883\u53d8\u91cf\u7ba1\u7406\u4f53\u7cfb<\/h3>\n<h4>4.1 echo \u5185\u5efa\u547d\u4ee4\u4e0e\u9000\u51fa\u7801 $?<\/h4>\n<p>\u8bfe\u4e0a\u8fd8\u63a2\u8ba8\u4e86 echo \u4f5c\u4e3a\u5185\u5efa\u547d\u4ee4\u7684\u5b9e\u73b0\u3002\u867d\u7136\u7cfb\u7edf\u91cc\u6709 \/bin\/echo \u8fd9\u4e2a\u5916\u90e8\u7a0b\u5e8f&#xff0c;\u4f46\u5728 Shell \u5185\u90e8\u5b9e\u73b0\u4e3a\u5185\u5efa\u547d\u4ee4\u6709\u4e24\u4e2a\u597d\u5904&#xff1a;<\/p>\n<ul>\n<li>\u63d0\u9ad8\u6548\u7387&#xff08;\u65e0\u9700 fork\/exec&#xff09;&#xff1b;<\/li>\n<li>\u652f\u6301\u7279\u6b8a\u53d8\u91cf\u89e3\u6790&#xff0c;\u5982 $? \u548c $VAR_NAME\u3002<\/li>\n<\/ul>\n<p>\u9000\u51fa\u7801&#xff08;$?&#xff09;\u7684\u5904\u7406\u673a\u5236&#xff1a;<br \/>\nShell \u9700\u7ef4\u62a4\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf last_exit_code&#xff0c;\u8bb0\u5f55\u6700\u8fd1\u4e00\u4e2a\u8fdb\u7a0b\u7684\u9000\u51fa\u72b6\u6001\u3002\u5f53\u6267\u884c echo $?&#xff08;\u7528\u4e8e\u8f93\u51fa\u4e0a\u4e00\u6761\u547d\u4ee4\u7684\u9000\u51fa\u72b6\u6001\u7801&#xff08;Exit Status&#xff09;&#xff09; \u65f6&#xff0c;\u89e3\u6790\u53c2\u6570\u8bc6\u522b $?&#xff0c;\u8f93\u51fa\u8be5\u503c&#xff0c;\u5e76\u5728\u8f93\u51fa\u540e\u91cd\u7f6e&#xff08;\u6e05\u96f6\u6216\u66f4\u65b0&#xff09;\u3002<\/p>\n<h4>4.2 \u73af\u5883\u53d8\u91cf\u8868\u7684\u521d\u59cb\u5316\u4e0e\u7ef4\u62a4<\/h4>\n<p>\u4e00\u4e2a\u771f\u6b63\u7684 Shell \u542f\u52a8\u65f6&#xff0c;\u9700\u8981\u4ece\u7236\u8fdb\u7a0b\u7ee7\u627f\u73af\u5883\u53d8\u91cf\u3002\u8bfe\u4e0a\u8001\u5e08\u4ecb\u7ecd\u4e86\u53cc\u8868\u7ed3\u6784&#xff1a;<\/p>\n<li>\u547d\u4ee4\u884c\u53c2\u6570\u8868&#xff08;argv&#xff09;&#xff1a;\u6bcf\u6b21\u6267\u884c\u547d\u4ee4\u65f6\u52a8\u6001\u53d8\u5316&#xff1b;<\/li>\n<li>\u73af\u5883\u53d8\u91cf\u8868&#xff1a;\u76f8\u5bf9\u7a33\u5b9a&#xff0c;Shell \u542f\u52a8\u65f6\u521d\u59cb\u5316\u3002<\/li>\n<p>\u542f\u52a8\u521d\u59cb\u5316\u6d41\u7a0b&#xff1a;<\/p>\n<ul>\n<li>\u901a\u8fc7\u5168\u5c40\u6307\u9488 environ \u7ee7\u627f\u7236\u8fdb\u7a0b\u73af\u5883\u53d8\u91cf&#xff1b;<\/li>\n<li>\u5206\u914d\u5185\u5b58\u6784\u5efa\u672c\u5730\u73af\u5883\u53d8\u91cf\u8868&#xff08;\u4e8c\u7ef4\u6570\u7ec4\u6216\u6307\u9488\u6570\u7ec4&#xff09;&#xff1b;<\/li>\n<li>\u8c03\u7528 putenv \u5c06\u672c\u5730\u8868\u4e2d\u7684\u53d8\u91cf\u5bfc\u51fa\u5230\u8fdb\u7a0b\u4e0a\u4e0b\u6587&#xff0c;\u786e\u4fdd\u5b50\u8fdb\u7a0b\u53ef\u7ee7\u627f\u3002<\/li>\n<\/ul>\n<p>export \u7684\u5b9e\u73b0&#xff1a;<br \/>\n\u89e3\u6790 export KEY&#061;VALUE \u540e&#xff0c;\u5728\u672c\u5730\u73af\u5883\u53d8\u91cf\u8868\u4e2d\u67e5\u627e Key\u3002\u82e5\u5b58\u5728\u5219\u66f4\u65b0 Value&#xff0c;\u82e5\u4e0d\u5b58\u5728\u5219\u65b0\u589e\u6761\u76ee&#xff0c;\u5e76\u540c\u6b65\u8c03\u7528 putenv \u5bfc\u51fa\u3002<\/p>\n<h4>4.3 \u522b\u540d&#xff08;alias&#xff09;\u6269\u5c55\u601d\u8def<\/h4>\n<p>&#x1f4cc;alias \u662f\u4e00\u79cd\u5728\u547d\u4ee4\u884c\u73af\u5883\u4e2d\u7528\u4e8e\u5b9a\u4e49\u5feb\u6377\u547d\u4ee4\u7684\u673a\u5236&#xff0c;\u5141\u8bb8\u7528\u6237\u4e3a\u590d\u6742\u7684\u547d\u4ee4\u6216\u547d\u4ee4\u7ec4\u5408\u521b\u5efa\u4e00\u4e2a\u7b80\u77ed\u7684\u522b\u540d\u3002<\/p>\n<p>\u8bfe\u4e0a\u8001\u5e08\u8fd8\u8865\u5145\u4e86\u4e00\u4e2a\u8fdb\u9636\u8bdd\u9898&#xff1a;\u5982\u4f55\u7528 std::map \u6216\u54c8\u5e0c\u8868\u7ef4\u62a4\u522b\u540d\u6620\u5c04\u5173\u7cfb&#xff08;\u5982 ll \u6620\u5c04\u5230 ls -a -l&#xff09;\u3002\u5728\u547d\u4ee4\u89e3\u6790\u9636\u6bb5\u5148\u68c0\u67e5\u522b\u540d\u8868&#xff0c;\u82e5\u547d\u4e2d\u5219\u66ff\u6362\u4e3a\u539f\u59cb\u547d\u4ee4\u540e\u518d\u6267\u884c\u3002\u8fd9\u4e3a Shell \u7684\u529f\u80fd\u5b8c\u6574\u6027\u63d0\u4f9b\u4e86\u6269\u5c55\u65b9\u5411\u3002<\/p>\n<hr \/>\n<h3>\u4e94\u3001\u4ece\u8fdb\u7a0b\u5230\u6587\u4ef6&#xff1a;Linux \u6587\u4ef6\u64cd\u4f5c\u7684\u5e95\u5c42\u8ba4\u77e5<\/h3>\n<p>\u89e3\u51b3\u5b8c cd \u95ee\u9898\u540e&#xff0c;\u8bfe\u7a0b\u7684\u91cd\u5fc3\u6084\u7136\u4ece\u8fdb\u7a0b\u7ba1\u7406\u5411\u6587\u4ef6\u7cfb\u7edf\u8fc7\u6e21\u3002\u8001\u5e08\u8f93\u51fa\u4e86\u4e00\u7cfb\u5217\u9700\u8981\u5efa\u7acb\u7684\u5e95\u5c42\u8ba4\u77e5&#xff1a;<\/p>\n<h4>5.1 \u6587\u4ef6\u7684\u672c\u8d28<\/h4>\n<p>\u201c\u6587\u4ef6 &#061; \u5185\u5bb9 &#043; \u5c5e\u6027&#xff08;\u5143\u6570\u636e&#xff09;\u3002\u201d<\/p>\n<p>\u5373\u4f7f\u4e00\u4e2a\u6587\u4ef6\u5927\u5c0f\u4e3a 0KB&#xff0c;\u5b83\u4f9d\u7136\u5360\u7528\u78c1\u76d8\u7a7a\u95f4\u2014\u2014\u56e0\u4e3a\u5c5e\u6027&#xff08;\u6743\u9650\u3001\u65f6\u95f4\u3001\u5927\u5c0f\u7b49&#xff09;\u5fc5\u987b\u88ab\u5b58\u50a8\u3002Linux \u4e0b&#034;\u4e00\u5207\u7686\u6587\u4ef6&#034;&#xff0c;\u952e\u76d8\u3001\u663e\u793a\u5668\u3001\u78c1\u76d8\u90fd\u88ab\u62bd\u8c61\u4e3a\u6587\u4ef6&#xff0c;\u7edf\u4e00\u901a\u8fc7 IO \u63a5\u53e3\u8bbf\u95ee\u3002<\/p>\n<h4>5.2 \u8c01\u6253\u5f00\u6587\u4ef6&#xff1f;<\/h4>\n<p>\u8fd9\u662f\u4e00\u4e2a\u770b\u4f3c\u7b80\u5355\u5374\u6781\u5bb9\u6613\u7b54\u9519\u7684\u95ee\u9898\u3002<\/p>\n<p>\u201c\u662f\u8fdb\u7a0b\u6253\u5f00\u6587\u4ef6\u3002\u201d<\/p>\n<p>\u4f60\u7684 C \u4ee3\u7801\u91cc\u5199\u4e86 fopen&#xff0c;\u4f46\u7f16\u8bd1\u597d\u7684\u4e8c\u8fdb\u5236\u7a0b\u5e8f\u5982\u679c\u6ca1\u8fd0\u884c&#xff0c;\u6587\u4ef6\u5e76\u672a\u88ab\u6253\u5f00\u3002\u53ea\u6709\u5f53\u8fdb\u7a0b\u8fd0\u884c\u8d77\u6765&#xff0c;\u6267\u884c\u5230 open \u6216 fopen \u65f6&#xff0c;\u6587\u4ef6\u624d\u7b97\u771f\u6b63\u88ab\u6253\u5f00\u3002\u56e0\u6b64&#xff0c;\u6587\u4ef6\u64cd\u4f5c\u7684\u4e3b\u4f53\u6c38\u8fdc\u662f\u8fdb\u7a0b\u3002<\/p>\n<h4>5.3 \u7cfb\u7edf\u8c03\u7528 vs \u5e93\u51fd\u6570<\/h4>\n<p>\u6211\u4eec\u65e5\u5e38\u4f7f\u7528\u7684 C\/C&#043;&#043; \u6587\u4ef6\u64cd\u4f5c\u51fd\u6570&#xff08;\u5982 fopen\u3001fprintf&#xff09;\u672c\u8d28\u4e0a\u662f\u5bf9\u7cfb\u7edf\u8c03\u7528&#xff08;\u5982 open\u3001read\u3001write&#xff09;\u7684\u5c01\u88c5\u3002\u8001\u5e08\u5f3a\u8c03&#xff1a;<\/p>\n<p>\u201c\u65e0\u8bba\u9876\u5c42\u5c01\u88c5\u591a\u4e48\u590d\u6742&#xff0c;\u5e95\u5c42\u53ea\u7528\u4e00\u5957\u7cfb\u7edf\u8c03\u7528\u3002\u201d<\/p>\n<p>\u5c01\u88c5\u7684\u4e3b\u8981\u4ef7\u503c\u5728\u4e8e\u63d0\u4f9b\u8de8\u5e73\u53f0\u517c\u5bb9\u6027\u548c\u7f13\u51b2\u673a\u5236\u3002<\/p>\n<h4>5.4 \u6807\u51c6 IO \u6d41\u4e0e\u91cd\u5b9a\u5411<\/h4>\n<p>\u8fdb\u7a0b\u542f\u52a8\u65f6&#xff0c;\u9ed8\u8ba4\u6253\u5f00\u4e09\u4e2a\u6807\u51c6\u6d41&#xff1a;<\/p>\n<ul>\n<li>stdin (0)&#xff1a;\u6807\u51c6\u8f93\u5165&#xff0c;\u9ed8\u8ba4\u5173\u8054\u952e\u76d8&#xff1b;<\/li>\n<li>stdout (1)&#xff1a;\u6807\u51c6\u8f93\u51fa&#xff0c;\u9ed8\u8ba4\u5173\u8054\u663e\u793a\u5668&#xff1b;<\/li>\n<li>stderr (2)&#xff1a;\u6807\u51c6\u9519\u8bef&#xff0c;\u9ed8\u8ba4\u5173\u8054\u663e\u793a\u5668\u3002<\/li>\n<\/ul>\n<p>\u8001\u5e08\u6307\u51fa\u4e00\u4e2a\u8bed\u8a00\u5c42\u7ec6\u8282&#xff1a;C \u7a0b\u5e8f\u542f\u52a8\u65f6&#xff0c;\u7f16\u8bd1\u5668\/runtime \u4f1a\u9ed8\u8ba4\u5e2e\u4f60 fopen \u6253\u5f00\u8fd9\u4e09\u4e2a\u6587\u4ef6&#xff0c;\u56e0\u6b64\u4f60\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 printf&#xff08;\u672c\u8d28\u4e0a\u662f\u5411 stdout \u5199\u5165&#xff09;\u3002<\/p>\n<p>\u91cd\u5b9a\u5411\u7684\u672c\u8d28&#xff1a;<\/p>\n<ul>\n<li>&gt;&#xff08;\u8986\u76d6&#xff09;&#xff1a;\u4ee5 w \u6a21\u5f0f\u6253\u5f00\u6587\u4ef6&#xff0c;\u6e05\u7a7a\u539f\u5185\u5bb9\u540e\u5199\u5165&#xff1b;<\/li>\n<li>&gt;&gt;&#xff08;\u8ffd\u52a0&#xff09;&#xff1a;\u4ee5 a (append) \u6a21\u5f0f\u6253\u5f00\u6587\u4ef6&#xff0c;\u5728\u672b\u5c3e\u5199\u5165\u3002<\/li>\n<\/ul>\n<h4>5.5 open \u7cfb\u7edf\u8c03\u7528\u4e0e\u4f4d\u56fe\u4f20\u53c2<\/h4>\n<p>\u63a5\u89e6\u5230\u5e95\u5c42 open \u51fd\u6570\u65f6&#xff0c;\u8001\u5e08\u63d0\u5230\u4e86\u4e00\u4e2a\u7cbe\u5999\u7684\u8bbe\u8ba1&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">open<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> <span class=\"token keyword\">char<\/span> <span class=\"token operator\">*<\/span>pathname<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> flags<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>flags \u4f7f\u7528**\u4f4d\u56fe&#xff08;Bitmask&#xff09;**\u65b9\u5f0f\u4f20\u9012\u591a\u4e2a\u6807\u5fd7&#xff0c;\u4f8b\u5982 O_RDONLY | O_CREAT\u3002\u5404\u6807\u5fd7\u5b8f\u5b9a\u4e49\u4e3a\u4e92\u65a5\u7684\u6bd4\u7279\u4f4d&#xff0c;\u901a\u8fc7\u6309\u4f4d\u6216\u7ec4\u5408&#xff08;\u67091\u53731&#xff0c;\u53cc0\u624d0&#xff09;\u3002<\/p>\n<h4>5.6 \u51e0\u4e2a\u5b9e\u7528\u7ec6\u8282<\/h4>\n<ul>\n<li>\u5b57\u7b26\u4e32\u5199\u5165\u6587\u4ef6&#xff1a;\u4e0d\u9700\u8981\u5199\u5165 \\\\0 \u7ed3\u675f\u7b26&#xff0c;\u56e0\u4e3a\u5b83\u662f C \u8bed\u8a00\u5185\u5b58\u5b57\u7b26\u4e32\u7684\u6807\u8bb0&#xff0c;\u800c\u975e\u6587\u4ef6\u5185\u5bb9\u5fc5\u9700\u3002&#xff08;\u8bed\u8a00\u5c42\u7684\u8bbe\u8ba1&#xff0c;\u9002\u7528\u4e8e\u8bed\u8a00\u5c42&#xff09;<\/li>\n<li>\u8bfb\u5199\u4f4d\u7f6e\u6307\u9488&#xff1a;\u6587\u4ef6\u5185\u90e8\u7ef4\u62a4\u8bfb\u5199\u504f\u79fb\u91cf\u3002\u82e5\u521a\u5199\u5165\u540e\u60f3\u8bfb\u53d6&#xff0c;\u5fc5\u987b\u4f7f\u7528 fseek \u8c03\u6574\u6307\u9488\u4f4d\u7f6e&#xff0c;\u5426\u5219\u53ef\u80fd\u8bfb\u53d6\u4e0d\u5230\u521a\u5199\u5165\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>\u516d\u3001\u603b\u7ed3&#xff1a;\u4e00\u4e2a Shell \u7684\u6210\u719f\u4e4b\u8def<\/h3>\n<p>\u8fd9\u4e00\u8d9f\u4ece&#034;120 \u884c\u57fa\u7840\u4ee3\u7801&#034;\u5230&#034;\u5185\u5efa\u547d\u4ee4\u5b8c\u6574\u5b9e\u73b0&#034;\u7684\u65c5\u7a0b&#xff0c;\u8ba9\u6211\u4eec\u6df1\u523b\u4f53\u4f1a\u5230&#xff1a;Shell \u4e0d\u662f\u7b80\u5355\u7684&#034;\u5b57\u7b26\u4e32\u62fc\u63a5 &#043; \u5b50\u8fdb\u7a0b\u8c03\u7528&#034;&#xff0c;\u800c\u662f\u4e00\u4e2a\u9700\u8981\u7cbe\u7ec6\u7ba1\u7406\u8fdb\u7a0b\u72b6\u6001\u3001\u73af\u5883\u53d8\u91cf\u548c\u6587\u4ef6\u5173\u7cfb\u7684\u7cfb\u7edf\u5de5\u5177\u3002<\/p>\n<h4>\u6838\u5fc3\u6536\u83b7\u56de\u987e&#xff1a;<\/h4>\n<li>\u5185\u5efa\u547d\u4ee4\u7684\u672c\u8d28&#xff1a;\u6539\u53d8 Shell \u81ea\u8eab\u72b6\u6001\u7684\u547d\u4ee4&#xff08;\u5982 cd\u3001export\u3001echo&#xff09;&#xff0c;\u5fc5\u987b\u7531\u7236\u8fdb\u7a0b\u4eb2\u81ea\u6267\u884c&#xff0c;\u7ed5\u8fc7 fork\/exec\u3002<\/li>\n<li>\u5065\u58ee\u6027\u610f\u8bc6&#xff1a;\u7a7a\u6307\u4ee4\u68c0\u6d4b&#xff08;argc &lt;&#061; 0&#xff09;\u3001\u8fd4\u56de\u503c\u89c4\u8303\u3001\u8fb9\u754c\u60c5\u51b5\u5904\u7406&#xff0c;\u662f\u5de5\u4e1a\u7ea7\u4ee3\u7801\u7684\u57fa\u672c\u7d20\u517b\u3002<\/li>\n<li>\u8def\u5f84\u540c\u6b65\u673a\u5236&#xff1a;chdir \u53ea\u6539\u5185\u6838\u6001\u7684 CWD&#xff0c;\u73af\u5883\u53d8\u91cf PWD \u9700\u8981\u624b\u52a8\u901a\u8fc7 getcwd &#043; putenv \u540c\u6b65\u3002<\/li>\n<li>\u73af\u5883\u53d8\u91cf\u53cc\u8868&#xff1a;\u547d\u4ee4\u884c\u53c2\u6570\u8868\u4e0e\u73af\u5883\u53d8\u91cf\u8868\u5206\u79bb&#xff0c;\u542f\u52a8\u65f6\u4ece environ \u7ee7\u627f\u5e76\u7ef4\u62a4\u672c\u5730\u526f\u672c\u3002<\/li>\n<li>\u6587\u4ef6\u7684\u8fdb\u7a0b\u89c6\u89d2&#xff1a;\u6587\u4ef6\u64cd\u4f5c\u7684\u672c\u8d28\u662f\u8fdb\u7a0b\u64cd\u4f5c&#xff1b;\u7cfb\u7edf\u8c03\u7528\u662f\u5e95\u5c42\u552f\u4e00\u63a5\u53e3&#xff1b;\u6807\u51c6\u6d41\u662f\u7a0b\u5e8f\u4e0e\u4e16\u754c\u7684\u9ed8\u8ba4\u6570\u636e\u901a\u9053\u3002<\/li>\n<hr \/>\n<p>\u5199\u5728\u6700\u540e&#xff1a;\u5982\u679c\u4f60\u4e5f\u66fe\u5bf9\u7740\u81ea\u5df1\u5199\u7684 Shell \u7591\u60d1&#034;\u4e3a\u4ec0\u4e48 cd \u4e0d\u8d77\u4f5c\u7528&#034;&#xff0c;\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u8ba9\u4f60\u8c41\u7136\u5f00\u6717\u3002\u7cfb\u7edf\u7f16\u7a0b\u7684\u9b45\u529b\u5c31\u5728\u4e8e&#xff0c;\u6bcf\u4e00\u4e2a\u770b\u4f3c\u7b80\u5355\u7684\u547d\u4ee4\u80cc\u540e&#xff0c;\u90fd\u85cf\u7740\u64cd\u4f5c\u7cfb\u7edf\u7cbe\u5bc6\u800c\u4e25\u8c28\u7684\u8bbe\u8ba1\u54f2\u5b66\u3002\u7ee7\u7eedcoding\u5427&#xff0c;\u4e0b\u4e00\u8282&#xff0c;\u6211\u4eec\u5c06\u6df1\u5165\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e0e\u5185\u6838\u6570\u636e\u7ed3\u6784&#xff0c;\u770b\u770b\u8fdb\u7a0b\u4e0e\u6587\u4ef6\u7a76\u7adf\u662f\u5982\u4f55&#034;\u7275\u624b&#034;\u7684\u3002<\/p>\n<p>\u201c\u61c2\u539f\u7406\u7684\u4eba\u5199\u4ee3\u7801&#xff0c;\u5199\u7684\u662f\u786e\u5b9a\u6027&#xff1b;\u4e0d\u61c2\u539f\u7406\u7684\u4eba\u5199\u4ee3\u7801&#xff0c;\u5199\u7684\u662f\u8fd0\u6c14\u3002\u201d \u613f\u6211\u4eec\u90fd\u80fd\u6210\u4e3a\u524d\u8005\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53 cd \u7a81\u7136\u5931\u6548&#xff1a;\u4e00\u6b21\u81ea\u5b9a\u4e49 Shell \u7684\u5185\u5efa\u547d\u4ee4\u6df1\u5ea6\u7a81\u56f4\u201c\u6211\u4eec\u5199\u4e86 120 \u884c\u4ee3\u7801&#xff0c;\u4ee5\u4e3a\u81ea\u5df1\u62e5\u6709\u4e86\u4e00\u4e2a Shell&#xff1b;\u76f4\u5230\u8f93\u5165 cd .. \u5374\u53d1\u73b0\u7eb9\u4e1d\u4e0d\u52a8&#xff0c;\u624d\u610f\u8bc6\u5230\u2014\u2014\u539f\u6765\u6211\u4eec\u53ea\u662f\u5728\u548c\u5b50\u8fdb\u7a0b\u2019\u73a9\u8fc7\u5bb6\u5bb6\u2019\u3002\u201d\u8fd9\u662f\u8bfe\u5802\u4e0a\u8001\u5e08\u629b\u51fa\u7684\u4e00\u4e2a\u7ecf\u5178\u573a\u666f\u3002\u4e0a\u8282\u8bfe&#xff0c;\u6211\u4eec\u5b8c\u6210\u4e86\u81ea\u5b9a\u4e49 Shell&#xff08;myshell&#xff09;\u7684\u57fa\u7840\u6846\u67b6&#xff0c;\u5927\u7ea6 120 \u884c\u4ee3\u7801&#xff0c;\u5b9e\u73b0\u4e86\u83b7\u53d6\u7528\u6237\u540d\u3001\u4e3b\u673a<\/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":[11820,352,58,323,43,44],"topic":[],"class_list":["post-115493","post","type-post","status-publish","format-standard","hentry","category-server","tag-atomgit","tag-bash","tag-linux","tag-323","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>\u3010Linux\u7cfb\u7edf\u3011\u3010cd\u5931\u6548\u80cc\u540e\u7684\u8fdb\u7a0b\u771f\u76f8\uff1a\u5185\u5efa\u547d\u4ee4\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f\u3011\u6d41\u98df\u822c\u6295\u5582 - \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\/115493.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Linux\u7cfb\u7edf\u3011\u3010cd\u5931\u6548\u80cc\u540e\u7684\u8fdb\u7a0b\u771f\u76f8\uff1a\u5185\u5efa\u547d\u4ee4\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5f53 cd \u7a81\u7136\u5931\u6548&#xff1a;\u4e00\u6b21\u81ea\u5b9a\u4e49 Shell \u7684\u5185\u5efa\u547d\u4ee4\u6df1\u5ea6\u7a81\u56f4\u201c\u6211\u4eec\u5199\u4e86 120 \u884c\u4ee3\u7801&#xff0c;\u4ee5\u4e3a\u81ea\u5df1\u62e5\u6709\u4e86\u4e00\u4e2a Shell&#xff1b;\u76f4\u5230\u8f93\u5165 cd .. \u5374\u53d1\u73b0\u7eb9\u4e1d\u4e0d\u52a8&#xff0c;\u624d\u610f\u8bc6\u5230\u2014\u2014\u539f\u6765\u6211\u4eec\u53ea\u662f\u5728\u548c\u5b50\u8fdb\u7a0b\u2019\u73a9\u8fc7\u5bb6\u5bb6\u2019\u3002\u201d\u8fd9\u662f\u8bfe\u5802\u4e0a\u8001\u5e08\u629b\u51fa\u7684\u4e00\u4e2a\u7ecf\u5178\u573a\u666f\u3002\u4e0a\u8282\u8bfe&#xff0c;\u6211\u4eec\u5b8c\u6210\u4e86\u81ea\u5b9a\u4e49 Shell&#xff08;myshell&#xff09;\u7684\u57fa\u7840\u6846\u67b6&#xff0c;\u5927\u7ea6 120 \u884c\u4ee3\u7801&#xff0c;\u5b9e\u73b0\u4e86\u83b7\u53d6\u7528\u6237\u540d\u3001\u4e3b\u673a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/115493.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-12T00:57:43+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=\"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\/115493.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/115493.html\",\"name\":\"\u3010Linux\u7cfb\u7edf\u3011\u3010cd\u5931\u6548\u80cc\u540e\u7684\u8fdb\u7a0b\u771f\u76f8\uff1a\u5185\u5efa\u547d\u4ee4\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-12T00:57:43+00:00\",\"dateModified\":\"2026-10-12T00:57:43+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/115493.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/115493.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/115493.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Linux\u7cfb\u7edf\u3011\u3010cd\u5931\u6548\u80cc\u540e\u7684\u8fdb\u7a0b\u771f\u76f8\uff1a\u5185\u5efa\u547d\u4ee4\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f\u3011\u6d41\u98df\u822c\u6295\u5582\"}]},{\"@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":"\u3010Linux\u7cfb\u7edf\u3011\u3010cd\u5931\u6548\u80cc\u540e\u7684\u8fdb\u7a0b\u771f\u76f8\uff1a\u5185\u5efa\u547d\u4ee4\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f\u3011\u6d41\u98df\u822c\u6295\u5582 - \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\/115493.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Linux\u7cfb\u7edf\u3011\u3010cd\u5931\u6548\u80cc\u540e\u7684\u8fdb\u7a0b\u771f\u76f8\uff1a\u5185\u5efa\u547d\u4ee4\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5f53 cd \u7a81\u7136\u5931\u6548&#xff1a;\u4e00\u6b21\u81ea\u5b9a\u4e49 Shell \u7684\u5185\u5efa\u547d\u4ee4\u6df1\u5ea6\u7a81\u56f4\u201c\u6211\u4eec\u5199\u4e86 120 \u884c\u4ee3\u7801&#xff0c;\u4ee5\u4e3a\u81ea\u5df1\u62e5\u6709\u4e86\u4e00\u4e2a Shell&#xff1b;\u76f4\u5230\u8f93\u5165 cd .. \u5374\u53d1\u73b0\u7eb9\u4e1d\u4e0d\u52a8&#xff0c;\u624d\u610f\u8bc6\u5230\u2014\u2014\u539f\u6765\u6211\u4eec\u53ea\u662f\u5728\u548c\u5b50\u8fdb\u7a0b\u2019\u73a9\u8fc7\u5bb6\u5bb6\u2019\u3002\u201d\u8fd9\u662f\u8bfe\u5802\u4e0a\u8001\u5e08\u629b\u51fa\u7684\u4e00\u4e2a\u7ecf\u5178\u573a\u666f\u3002\u4e0a\u8282\u8bfe&#xff0c;\u6211\u4eec\u5b8c\u6210\u4e86\u81ea\u5b9a\u4e49 Shell&#xff08;myshell&#xff09;\u7684\u57fa\u7840\u6846\u67b6&#xff0c;\u5927\u7ea6 120 \u884c\u4ee3\u7801&#xff0c;\u5b9e\u73b0\u4e86\u83b7\u53d6\u7528\u6237\u540d\u3001\u4e3b\u673a","og_url":"https:\/\/www.wsisp.com\/helps\/115493.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-12T00:57:43+00:00","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\/115493.html","url":"https:\/\/www.wsisp.com\/helps\/115493.html","name":"\u3010Linux\u7cfb\u7edf\u3011\u3010cd\u5931\u6548\u80cc\u540e\u7684\u8fdb\u7a0b\u771f\u76f8\uff1a\u5185\u5efa\u547d\u4ee4\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-12T00:57:43+00:00","dateModified":"2026-10-12T00:57:43+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/115493.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/115493.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/115493.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Linux\u7cfb\u7edf\u3011\u3010cd\u5931\u6548\u80cc\u540e\u7684\u8fdb\u7a0b\u771f\u76f8\uff1a\u5185\u5efa\u547d\u4ee4\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f\u3011\u6d41\u98df\u822c\u6295\u5582"}]},{"@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\/115493","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=115493"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/115493\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=115493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=115493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=115493"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=115493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}