<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Linux/macOS - Shell - How to Redirect stderr to stdout in Terminal or scripts - Linux Software				            </title>
            <link>https://www.tweaking4all.com/forum/linux-software/linux-macos-shell-how-to-redirect-stderr-to-stdout-in-terminal-or-scripts/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Tue, 09 Jun 2026 02:06:25 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>Linux/macOS - Shell - How to Redirect stderr to stdout in Terminal or scripts</title>
                        <link>https://www.tweaking4all.com/forum/linux-software/linux-macos-shell-how-to-redirect-stderr-to-stdout-in-terminal-or-scripts/#post-4438</link>
                        <pubDate>Sat, 24 Sep 2022 09:39:29 +0000</pubDate>
                        <description><![CDATA[Terminal/Shell commands can use 3 types of input/output &quot;channels&quot; or I/O streams. Each stream is represented by a numeric file descriptor:
0 - stdin,  the standard input stream.
1 - stdou...]]></description>
                        <content:encoded><![CDATA[<p>Terminal/Shell commands can use 3 types of input/output "channels" or I/O streams. <br />Each stream is represented by a numeric file descriptor:<br /><br /></p>
<pre contenteditable="false">0 - stdin,  the standard input stream.
1 - stdout, the standard output stream.
2 - stderr, the standard error stream.</pre>
<p>(A file descriptor is just a number representing an open file)<br /><br />The input stream provides information to the program, and the output stream ... well, outputs data haha.<br />This is where it gets tricky at times though.</p>
<p>Output is done either through the standard output (stdout) or through the "error channel" (stderr).<br />I refer to these as <em>channels</em>, but that is just to clarify this to those unfamiliar with I/O streams.</p>
<p>Under most circumstances this all works just fine, just sometimes it doesn't when piping output from program/command one to another.</p>
<p>For example: <br />Normally the standard output is used for piping (passing on) information as an input for another program.<br />However, sometimes we want the error info instead of the standard output info.</p>
<p>We can however redirect the error channel (stderr) to the standard output channel (stdout) and vice versa.</p>
<p>For example, this will redirect (<strong>&gt;</strong>) stderr (<strong>2</strong>) to stdout (<strong>1</strong>):</p>
<pre contenteditable="false">2&gt;&amp;1</pre>
<p>You can combine this in your sequence of commands.</p>
<p>For example:</p>
<pre contenteditable="false">somecommand 2&gt;&amp;1 &gt; somefile.txt</pre>
<p>The output to the error channel (stderr=2), from <strong>somecommand</strong> will be redirected (<strong>&gt;</strong>) to the standard output (<strong>1</strong>), which then will be redirected (<strong>&gt;</strong>) to the file somerfile.txt</p>
<p> </p>
<p>Example for Mac users; <strong>hdiutil</strong> outputs all its info to stderr. With regular use you won't notice this and everything looks normal.<br />However, when wanting to redirect the output, the <strong>hdiutil</strong> output will result in a blank file. Zero output.</p>
<p>This however will output the stderr as regular output:</p>
<pre contenteditable="false">hdiutil info 2&gt;&amp;1</pre>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/linux-software/">Linux Software</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/linux-software/linux-macos-shell-how-to-redirect-stderr-to-stdout-in-terminal-or-scripts/#post-4438</guid>
                    </item>
							        </channel>
        </rss>
		