Three Standard Streams

Input and output in the Linux environment is distributed across three streams:

<aside> 💡 During standard interactions between the user and the terminal, standard input is transmitted through the user’s keyboard. Standard output and standard error are displayed on the user’s terminal as text. Collectively, the three streams are referred to as the standard streams.

</aside>

Stream Redirection

Used to redirect command output to files.

Overwrite

> - standard output < - standard input 2> - standard error

Append

>> - standard output << - standard input 2>> - standard error

<aside> 💡 The overwrite commands write standard output to a file. If a non-existent file is targetted (either by a single-bracket or double-bracket command), a new file with that name will be created prior to writing.

</aside>

Pipes

Used to redirect a stream from one command to another. When a program’s standard output is sent to another through a pipe, the first program’s data, which is received by the second program, will not be displayed on the terminal. Only the filtered data returned by the second program will be displayed.

ls | less

Filters

Filters are commands that alter piped redirection and output. Note that filter commands are also standard Linux commands that can be used without pipes.

find [path] [expression]
grep [options] pattern [file...]
tee [OPTIONS] [FILE]
tr [OPTION] SET1 [SET2]
wc [options] [file(s)]