Streams, Pipes, Redirects

In Linux/Unix everyting is a file.

Standard I/O

Control input, output and error information via file descriptors:

Standard input (stdin)
This is the text input stream. It is also known as file descriptor 0.

Standard output (stdout)
This is the text output stream for normal program output. It is also known as file descriptor 1.

Standard error (stderr)
This exclusivly used for error output. It is also known as file descriptor 2.

Pipes

Tie the output of one program to the input of another program with a pipe (|)

Redirection

Redirection can occur while piping from or to a commands output/input. Or your can redirect to or from files with the redirection operators < and >

> creates files, < reads from files and >> appends to files.
redirectsyntax (bash)
pipe stdout from cmd1 to cmd2 cmd1 | cmd2
pipe stdout and stderr from cmd1 to cmd2 cmd1 2>&1 | cmd2
send stdout to file cmd > file
cmd 1> file
send stderr to file cmd 2> file
send both stdout and sterr to file cmd > file 2>&1
send stdout to file1 and stderr to file2 cmd > file1 2> file2
recieve stdin from file cmd < file
append stdout to file cmd >> file
cmd 1>> file
append stderr to file cmd 2>> file
append both stdout and stderr to file cmd > file 2>&1
discard stdout and stderr from cmd cmd > /dev/null 2>&1
shell/streams_pipes_redirects.txt · Last modified: 2014-03 by tb
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready