More about redirection

There are three streams of communication between a program and its environment:

Redirection illustration:

Process redirection diagram

Redirecting StdErr

[user@host docs]$ wc *.txt not_a_file > txt_list 2> txt_list_err

2> redirects any error messages created by a command

Output redirection and piping

When we run the command ‘ls -l’ both the stdout and stderr are output on the terminal screen.

ls -l

Directory structure

If we redirect the output of ls -l the stdout is written to list_of_files and stderr is still output to the terminal screen.

ls -l > list_of_files

Directory structure

Redirecting input

You can also redirect standard input to a command, using < to send the contents of a file in place of command line input.

[user@host docs]$ bc < some-maths.txt
3.14285714285714285714
9.99
16.66666666666666666666
10.312567

The command bc allows calculations with floating point numbers.

Next activity: Assessments - Pipes and Redirection Quiz.