Output redirection

> >> 2>

Write a command's output to a file instead of the screen

How it works

A command normally prints its result on screen. > sends that output to a file instead: ls > files.txt. If the file does not exist it is created; if it does, its old contents are wiped.

>> appends the output to the end of the file and leaves what is there alone, which is how logs are kept. Errors go to a separate stream (stderr) and do not end up in the file with >; 2> is for them. To collect both output and errors in one file, write command > file 2>&1.

Careful. > wipes the file without warning. Mixing up > and >> is a common way to lose a log or a config.

Syntax

<command> > <file>
<command> >> <file>
<command> 2> <file>
<command> > <file> 2>&1

Examples

Related commands

Practise · All commands