<p>I'm trying to redirect the java compiler output to a file. 
I thought it's supposed to be:</p>

<pre><code>javac file.java &gt; log.txt
</code></pre>

<p>or something. Instead, I see all the output on the terminal and nothing in log.txt!</p>

<p>Also, if I want to log errors too, do I do</p>

<pre><code>javac file.java 2&gt;&amp;1 &gt; log.txt
</code></pre>

<p>?</p>

```
```
javac file.java 2> log.txt
```
```
The reason is that you have
two
output file descriptors instead of one. The usual one is stdout, which you can redirect with > and it's supposed to be used for resulting output. The second one, stderr, is meant for human readable output like warnings, errors, current status etc., this one is redirected with 2>.
Your second line, using 2>&1, redirects stderr to stdout and finally stdout into log.txt.