Skip to content
koalaman edited this page Nov 20, 2014 · 8 revisions

The order of the 2>&1 and the redirect matters. The 2>&1 has to be last.

Problematic code:

firefox 2>&1 > /dev/null

Correct code:

firefox > /dev/null 2>&1

Rationale:

Redirections are handled in order.

The problematic code means "Point stderr to where stdout is currently pointing (the terminal). Then point stdout to /dev/null".

The correct code means "Point stdout to /dev/null. Then point stderr to where stdout is currently pointing (/dev/null).".

Contraindications

If you want stderr as stdout and stdout to a file, you can ignore this message.

Clone this wiki locally