{"id":8810,"date":"2022-03-25T11:34:33","date_gmt":"2022-03-25T16:34:33","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=8810"},"modified":"2022-03-25T11:40:57","modified_gmt":"2022-03-25T16:40:57","slug":"2-dev-null","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=8810","title":{"rendered":"2>\/dev\/null"},"content":{"rendered":"<p>A few times now, I&#8217;ve encountered individuals with cron jobs or bash scripts where a command execution ends in <tt>2&gt;\/dev\/null<\/tt> &#8230; and the individual is stymied by the fact it&#8217;s not working but there&#8217;s no clue as to <em>why.<\/em> The error output is being sent into a big black hole never to escape!<\/p>\n<p>The trick here is to understand file descriptors &#8212; 1 is basically a shortcut name for STDOUT and 2 is basically a shortcut name for STDERR (0 is STDIN, although that&#8217;s not particularly relevant here).\u00a0 So <tt>2&gt;\/dev\/null<\/tt> says &#8220;take all of the STDERR stuff and redirect it to \/dev\/null&#8221;.<\/p>\n<p>Sometimes you&#8217;ll see <em>bot<\/em><em>h<\/em> STDERR and STDOUT being redirected either to a file or to \/dev\/null &#8212; in that case you will see 2&gt;&amp;1 where the ampersand prior to the &#8220;1&#8221; indicates the stream is being redirected to a file descriptor (<tt>2&gt;1<\/tt> would direct STDOUT to a file named &#8220;1&#8221;) &#8212; so <tt>&gt;\/dev\/null 2&gt;&amp;1<\/tt> is the normal way you&#8217;d see it written. Functionally, <tt>&gt;\/dev\/null 1&gt;&amp;2<\/tt> would be the same thing &#8230; but redirecting all <em>output<\/em> into <em>error<\/em> is, conceptually, a little odd.<\/p>\n<p>To visualize all of this, use a command that will output something to both STDERR and STDOUT &#8212; for clarify, I&#8217;ve used &#8220;1&gt;\/dev\/null&#8221; (redirect STDOUT to \/devnull) in conjunction with 2&gt;&amp;1 (redirect STDERR to STDOUT). As written in the text above, the number 1 is generally omitted and just <tt>&gt;\/dev\/null<\/tt> is written.<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/?attachment_id=8815\" rel=\"attachment wp-att-8815\">\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8815\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2022\/03\/FileDescriptorsVisualization.png\" alt=\"\" width=\"624\" height=\"145\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2022\/03\/FileDescriptorsVisualization.png 624w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2022\/03\/FileDescriptorsVisualization-300x70.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few times now, I&#8217;ve encountered individuals with cron jobs or bash scripts where a command execution ends in 2&gt;\/dev\/null &#8230; and the individual is stymied by the fact it&#8217;s not working but there&#8217;s no clue as to why. The error output is being sent into a big black hole never to escape! The trick &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,30],"tags":[632,671,294,633,634],"class_list":["post-8810","post","type-post","status-publish","format-standard","hentry","category-coding","category-system-administration","tag-bash","tag-bash-script","tag-linux","tag-script","tag-shell-script"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8810"}],"version-history":[{"count":4,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8810\/revisions"}],"predecessor-version":[{"id":8816,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8810\/revisions\/8816"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}