Linuxlab

Output redirection in Linux: > and >>

Updated July 3, 2026

Output redirection sends a command's output to a file instead of the screen.

Syntax

command > file     # overwrite the file with the output
command >> file    # append to the end

Common cases

echo hello > out.txt     # create or overwrite
echo world >> out.txt    # append a line to the end
ls /nope 2> err.txt      # the error stream (2) to a file
make > log.txt 2>&1      # both output and errors to one file

How it works: the three standard streams

Every process has three standard streams: input (0), output (1) and errors (2). > redirects stream 1, 2> redirects stream 2, and 2>&1 means 'stream 2 to wherever stream 1 goes'. So > file 2>&1 gathers both the normal output and the errors into one file. A single > overwrites the whole file, while >> appends to the end.

Used in

You need this in the lesson Streams and pipelines. The theory is the chapter Streams, redirection, pipelines.

See also

Pipes and filters, cat, head, tail.

Try it

Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand - the container is deleted when you leave.