Redirection works fine if you only need to redirect streams to and from files, but if you need to chain commands together that read and write to the default file handles, then you need to use pipes . Pipes connect the stdout of one command to the stdin of the command that is next in the chain. As an example, suppose that you wish to concatenate three files, sort the contents of the files, then display the output a page at a time on the terminal screen:
cat file1 file2 file3 | sort | more
In this example, cat's stdout is piped into sort's stdin, and sort's stdout is piped into more's stdin. Since no pipe exists after the last command, output goes to the default stdout.
If you add an ampersand to the pipe operator (
), stderr will also be redirected to the next command's stdin.