{"id":1022,"date":"2022-06-19T22:20:11","date_gmt":"2022-06-19T14:20:11","guid":{"rendered":"http:\/\/175.24.184.226\/?p=1022"},"modified":"2022-06-19T22:20:11","modified_gmt":"2022-06-19T14:20:11","slug":"nohup-dev-null-21%e8%be%93%e5%87%ba%e9%87%8d%e5%ae%9a%e5%90%91","status":"publish","type":"post","link":"\/?p=1022","title":{"rendered":"nohup \/dev\/null 2>&#038;1\u8f93\u51fa\u91cd\u5b9a\u5411"},"content":{"rendered":"<hr \/>\n<hr \/>\n<hr \/>\n<pre><code class=\"language-bash\">nohup python3 test.py  &gt;\/dev\/null 2&gt;&amp;1 &amp;<\/code><\/pre>\n<p>Linux shell\u4e2d\u6709\u4e09\u79cd\u8f93\u5165\u8f93\u51fa\uff0c\u5206\u522b\u4e3a\u6807\u51c6\u8f93\u5165\uff0c\u6807\u51c6\u8f93\u51fa\uff0c\u9519\u8bef\u8f93\u51fa\uff0c\u5206\u522b\u5bf9\u5e940\uff0c1\uff0c2\u3002\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u8f93\u51fa\u91cd\u5b9a\u5411&gt;\uff08\u6216&gt;&gt;\uff0c\u8868\u793a\u8ffd\u52a0\uff09\u5c06\u67d0\u79cd\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u5176\u4ed6\u5730\u65b9\uff0c\u5982\u8bbe\u5907\uff0c\u6587\u4ef6\uff0c\u6bd4\u5982:<\/p>\n<pre><code class=\"language-bash\">ls &gt; ls.log  #\u6807\u51c6\u8f93\u51fa\u91cd\u5b9a\u5411\nls 2&gt; ls.log #\u6807\u51c6\u9519\u8bef\u91cd\u5b9a\u5411\nls &gt; \/dev\/null #\u91cd\u5b9a\u5411\u5230null\u8bbe\u5907\uff0c\u76f8\u5f53\u4e8e\u76f4\u63a5\u5ffd\u7565\u8f93\u51fa<\/code><\/pre>\n<p>\u4f46\u662f\uff0c\u6709\u65f6\u5019\uff0c\u6211\u4eec\u60f3\u628a\u6807\u51c6\u8f93\u51fa\u4ee5\u53ca\u9519\u8bef\u8f93\u51fa\u4e00\u8d77\u91cd\u5b9a\u5411\u67d0\u4e2a\u6587\u4ef6\uff0c\u8fd9\u662f\u53ef\u4ee5\u901a\u8fc7 2&gt;&amp;1 \u5b9e\u73b0\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u4e24\u4e2a\u540c\u65f6\u91cd\u5b9a\u5411\u5230\u67d0\u4e2a\u6587\u4ef6<\/p>\n<pre><code class=\"language-bash\">ls &gt;ls.log 2&gt;&amp;1 \/\/\u6807\u51c6\u8f93\u51fa\u91cd\u5b9a\u5411\u5230ls.log,\u800c\u9519\u8bef\u53c8\u91cd\u5b9a\u5411\u5230\u6807\u51c6\u8f93\u51fa\uff0c\u8fd9\u4e24\u4e2a\u4f4d\u7f6e\u4e0d\u53ef\u6362\nls 2&gt;&gt;ls.log 1&gt;&gt;ls.log<\/code><\/pre>\n<p>\u5148\u8bf4\u4e00\u4e0blinux\u91cd\u5b9a\u5411\uff1a<br \/>\n0\u30011\u548c2\u5206\u522b\u8868\u793a\u6807\u51c6\u8f93\u5165\u3001\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u4fe1\u606f\u8f93\u51fa\uff0c\u53ef\u4ee5\u7528\u6765\u6307\u5b9a\u9700\u8981\u91cd\u5b9a\u5411\u7684\u6807\u51c6\u8f93\u5165\u6216\u8f93\u51fa\u3002<br \/>\n\u5728\u4e00\u822c\u4f7f\u7528\u65f6\uff0c\u9ed8\u8ba4\u7684\u662f\u6807\u51c6\u8f93\u51fa\uff0c\u65e21.\u5f53\u6211\u4eec\u9700\u8981\u7279\u6b8a\u7528\u9014\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u6807\u53f7\u3002\u4f8b\u5982\uff0c\u5c06\u67d0\u4e2a\u7a0b\u5e8f\u7684\u9519\u8bef\u4fe1\u606f\u8f93\u51fa\u5230log\u6587\u4ef6\u4e2d\uff1a.\/program 2&gt;log\u3002\u8fd9\u6837\u6807\u51c6\u8f93\u51fa\u8fd8\u662f\u5728\u5c4f\u5e55\u4e0a\uff0c\u4f46\u662f\u9519\u8bef\u4fe1\u606f\u4f1a\u8f93\u51fa\u5230log\u6587\u4ef6\u4e2d\u3002<br \/>\n\u53e6\u5916\uff0c\u4e5f\u53ef\u4ee5\u5b9e\u73b00\uff0c1\uff0c2\u4e4b\u95f4\u7684\u91cd\u5b9a\u5411\u30022&gt;&amp;1\uff1a\u5c06\u9519\u8bef\u4fe1\u606f\u91cd\u5b9a\u5411\u5230\u6807\u51c6\u8f93\u51fa\u3002<br \/>\nLinux\u4e0b\u8fd8\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u6587\u4ef6\/dev\/null\uff0c\u5b83\u5c31\u50cf\u4e00\u4e2a\u65e0\u5e95\u6d1e\uff0c\u6240\u6709\u91cd\u5b9a\u5411\u5230\u5b83\u7684\u4fe1\u606f\u90fd\u4f1a\u6d88\u5931\u5f97\u65e0\u5f71\u65e0\u8e2a\u3002\u8fd9\u4e00\u70b9\u975e\u5e38\u6709\u7528\uff0c\u5f53\u6211\u4eec\u4e0d\u9700\u8981\u56de\u663e\u7a0b\u5e8f\u7684\u6240\u6709\u4fe1\u606f\u65f6\uff0c\u5c31\u53ef\u4ee5\u5c06\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\/dev\/null\u3002<\/p>\n<p>\u5982\u679c\u60f3\u8981\u6b63\u5e38\u8f93\u51fa\u548c\u9519\u8bef\u4fe1\u606f\u90fd\u4e0d\u663e\u793a\uff0c\u5219\u8981\u628a\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u90fd\u91cd\u5b9a\u5411\u5230\/dev\/null\uff0c \u4f8b\u5982\uff1a<\/p>\n<p><code># ls 1&gt;\/dev\/null 2&gt;\/dev\/null<\/code><\/p>\n<p>\u8fd8\u6709\u4e00\u79cd\u505a\u6cd5\u662f\u5c06\u9519\u8bef\u91cd\u5b9a\u5411\u5230\u6807\u51c6\u8f93\u51fa\uff0c\u7136\u540e\u518d\u91cd\u5b9a\u5411\u5230 \/dev\/null\uff0c\u4f8b\u5982\uff1a<\/p>\n<p><code># ls &gt;\/dev\/null 2&gt;&amp;1<\/code><\/p>\n<p>\u6ce8\u610f\uff1a\u6b64\u5904\u7684\u987a\u5e8f\u4e0d\u80fd\u66f4\u6539\uff0c\u5426\u5219\u8fbe\u4e0d\u5230\u60f3\u8981\u7684\u6548\u679c\uff0c\u6b64\u65f6\u5148\u5c06\u6807\u51c6\u8f93\u51fa\u91cd\u5b9a\u5411\u5230 \/dev\/null\uff0c\u7136\u540e\u5c06\u6807\u51c6\u9519\u8bef\u91cd\u5b9a\u5411\u5230\u6807\u51c6\u8f93\u51fa\uff0c\u7531\u4e8e\u6807\u51c6\u8f93\u51fa\u5df2\u7ecf\u91cd\u5b9a\u5411\u5230\u4e86\/dev\/null\uff0c\u56e0\u6b64\u6807\u51c6\u9519\u8bef\u4e5f\u4f1a\u91cd\u5b9a\u5411\u5230\/dev\/null\uff0c\u4e8e\u662f\u4e00\u5207\u9759\u6084\u6084:-)<\/p>\n<hr \/>\n<p>\u7531\u4e8e\u4f7f\u7528nohup\u65f6\uff0c\u4f1a\u81ea\u52a8\u5c06\u8f93\u51fa\u5199\u5165nohup.out\u6587\u4ef6\u4e2d\uff0c\u5982\u679c\u6587\u4ef6\u5f88\u5927\u7684\u8bdd\uff0cnohup.out\u5c31\u4f1a\u4e0d\u505c\u7684\u589e\u5927\uff0c\u8fd9\u662f\u6211\u4eec\u4e0d\u5e0c\u671b\u770b\u5230\u7684\uff0c\u56e0\u6b64\uff0c\u53ef\u4ee5\u5229\u7528\/dev\/null\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p><code>nohup .\/program &gt;\/dev\/null 2&gt;log &amp;<\/code><\/p>\n<p>\u5982\u679c\u9519\u8bef\u4fe1\u606f\u4e5f\u4e0d\u60f3\u8981\u7684\u8bdd\uff1a<\/p>\n<p><code>nohup .\/program &gt;\/dev\/null 2&gt;&amp;1 &amp;<\/code><\/p>\n<pre><code class=\"language-bash\">cmd1 |cmd2 \uff1a pipe\uff0c\u5c06cmd1 \u7684\u6807\u51c6\u8f93\u51fa\u4f5c\u4e3acmd2 \u7684\u6807\u51c6\u8f93\u5165\n>file \uff1a\u5c06\u6807\u51c6\u8f93\u51fa\u91cd\u5b9a\u5411\u5230file\n>&lt;file \uff1a\u5c06file\u4f5c\u4e3a\u6807\u51c6\u8f93\u5165\n>\n>&gt;file \uff1a\u5c06\u6807\u51c6\u8f93\u51fa\u91cd\u5b9a\u5411\u5230file\uff0c\u5982\u679cfile\u5b58\u5728\uff0cappend\u5230\u6587\u4ef6\u4e2d\uff0c\u5373\u9644\u52a0\u5230\u6587\u4ef6\u7684\u540e\u9762\uff0c\u800c\u4e0d\u662f\u8986\u76d6\u6587\u4ef6\n>&gt;|file \uff1a\u5f3a\u5236\u5c06\u6807\u51c6\u8f93\u51fa\u91cd\u5b9a\u5411\u5230file\uff0c\u5373\u4f7fnoclobber\u8bbe\u7f6e\u3002\u5f53\u8bbe\u7f6e\u73af\u5883\u53d8\u91cfset \u2013o noclobber\uff0c\u5c06\u7981\u6b62\u91cd\u5b9a\u5411\u5230\u4e00\u4e2a\u5df2\u7ecf\u5b58\u5728\u7684\u6587\u4ef6\u4e2d\uff0c\u907f\u514d\u6587\u4ef6\u88ab\u8986\u76d6\u3002\n>&gt;n &gt;|file \uff1a\u5f3a\u5236\u5c06\u6587\u4ef6\u63cf\u8ff0\u7b26n\u91cd\u5b9a\u5411\u5230file\uff0c\u5373\u4f7fnoclobber\u6253\u5f00\n>&gt;&lt;&gt;file \uff1a\u5c06file\u4f5c\u4e3a\u6807\u51c6\u8f93\u5165\u548c\u6807\u51c6\u8f93\u51fa\u3002\u901a\u5e38\u7528\u4e8e\u8bbe\u5907\u6587\u4ef6\uff08\/dev\u4e0b\u9762\u7684\u6587\u4ef6\uff09\uff0c\u5e95\u5c42\u7cfb\u7edf\u7a0b\u5e8f\u5458\u53ef\u7528\u4e4b\u6d4b\u8bd5\u8bbe\u5907\u9a71\u52a8\uff0c\u5176\u4ed6\u7684\u5f88\u5c11\u7528\u3002\n>&gt;n &lt;&gt;file \uff1a\u5c06file\u4f5c\u4e3a\u6587\u4ef6\u63cf\u8ff0\u7b26n\u7684\u8f93\u5165\u548c\u8f93\u51fa\n>&gt;&lt;&lt;label \uff1aHere-document; see text \u3002\u5c06shell\u7684\u6807\u51c6\u8f93\u5165\u4f5c\u4e3a\u547d\u4ee4\u7684\u8f93\u5165\uff0c\u76f4\u5230\u884c\u4e2d\u4e4b\u5305\u542blabel\u3002\u8fd9\u4e2d\u95f4\u7684\u8f93\u5165\u6210\u4e3ahere-document\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002\u6211\u4eec\u8ba9\u4eba\u4f7f\u7528cat &gt;&gt; file\u7684\u65b9\u5f0f\uff0c\u901a\u8fc7\u6807\u51c6\u8f93\u5165\u5728\u6587\u4ef6\u4e2d\u9644\u52a0\u5185\u5bb9\u3002\n>&gt;n&gt;file \uff1a\u5c06\u6587\u4ef6\u63cf\u8ff0\u7b26n\u91cd\u5b9a\u5411\u5230file\n>&gt;n \uff1a\u5c06file\u4f5c\u4e3a\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u8f93\u5165\n>&gt;n&gt;&gt;file \uff1a\u5c06\u6587\u4ef6\u63cf\u8ff0\u7b26n\u7684\u8f93\u51fa\u91cd\u5b9a\u5411\u5230file\uff0c\u5982\u679cfile\u5b58\u5728\uff0c\u5c06\u8f93\u51faappend\u5230\u6587\u4ef6\u540e\u9762\n>&gt;n&gt;&amp; \uff1a\u5c06\u6807\u51c6\u8f93\u51fa\u590d\u5236\u5230\u6587\u4ef6\u63cf\u8ff0\u7b26n\uff08Duplicate standard output to file descriptor n\uff09\n>&gt;n&lt;&amp; \uff1a\u4ece\u6587\u4ef6\u63cf\u8ff0\u7b26n\u590d\u5236\u6807\u51c6\u8f93\u5165\uff08Duplicate standard input from file descriptor n\uff09\n>&gt;n&gt;&amp;m \uff1a\u6587\u4ef6\u63cf\u8ff0\u5b57n\u5c06\u4e00\u4e2acopy\u81f3\u6587\u4ef6\u63cf\u8ff0\u5b57m\uff08File descriptor n is made to be a copy of the output file descriptor\uff09\n>&gt;n&lt;&amp;m \uff1a\u6587\u4ef6\u63cf\u8ff0\u5b57n\u4f5c\u4e3a\u6587\u4ef6\u63cf\u8ff0\u5b57m\u4e2d\u7684\u4e00\u4e2a\u62f7\u8d1d\uff08File descriptor n is made to be a copy of the input file descriptor\uff09\n>&gt;&amp;&gt;file \uff1a \u5c06\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u5b9a\u5411\u81f3\u6587\u4ef6file\n>&gt;&lt;&amp;- \uff1a \u5173\u95ed\u6807\u51c6\u8f93\u5165\n>&gt;&amp;- \uff1a \u5173\u95ed\u6807\u51c6\u8f93\u51fa\n>&gt;n&gt;&amp;- \uff1a \u5173\u95ed\u6587\u4ef6\u63cf\u8ff0\u5b57\u4f5c\u4e3a\u8f93\u51fa\uff08Close the output from file descriptor n\uff09\n>&gt;n&lt;&amp;- \uff1a\u5173\u95ed\u6587\u4ef6\u63cf\u8ff0\u5b57\u4f5c\u8f93\u5165\uff08Close the input from file descriptor n\uff09\n>&gt;n&gt;&amp;word\uff1a If n is not specified, the standard output (file descriptor 1) is used. If the digits in word do not specify a file descriptor open for output, a redirection error occurs. As a special case, if n is omitted, and word does not expand to one or more digits, the standard output and standard error are redirected as described previously.\n>&gt;n&lt;&amp;word \uff1a If word expands to one or more digits, the file descriptor denoted by n is made to be a copy of that file descriptor. If the digits in word do not specify a file descriptor open for input, a redirection error occurs. If word evaluates to -, file descriptor n is closed. If n is not specified, the standard input (file descriptor 0) is used.\n>&gt;n&gt;&amp;digit- \uff1a Moves the file descriptor digit to file descriptor n, or the standard output (file descriptor 1) if n is not specified.\n>&gt;n&lt;&amp;digit- \uff1a Moves the file descriptor digit to file descriptor n, or the standard input (file descriptor 0) if n is not specified. digit is closed after being duplicated to n.<\/code><\/pre>\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<br \/>\n\u7248\u6743\u58f0\u660e\uff1a\u672c\u6587\u4e3aCSDN\u535a\u4e3b\u300cEddie-Wang\u300d\u7684\u539f\u521b\u6587\u7ae0\uff0c\u9075\u5faaCC 4.0 BY-SA\u7248\u6743\u534f\u8bae\uff0c\u8f6c\u8f7d\u8bf7\u9644\u4e0a\u539f\u6587\u51fa\u5904\u94fe\u63a5\u53ca\u672c\u58f0\u660e\u3002<br \/>\n\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/blog.csdn.net\/wangchaox123\/article\/details\/90670352\">https:\/\/blog.csdn.net\/wangchaox123\/article\/details\/90670352<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>nohup python3 test.py &gt;\/dev\/null 2&gt;&amp;1 &amp; Linux shell\u4e2d\u6709\u4e09   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[14],"tags":[15,56],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1022"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1022"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1022\/revisions"}],"predecessor-version":[{"id":1023,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1022\/revisions\/1023"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1022"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}