| is a “pipe.” The | takes the standard output of the command on the left, and pipes it as standard input to the command on the right. You can think of this as “command to command” redirection.

$ cat volcanoes.txt | wc

Above, the output of cat volcanoes.txt becomes the standard input of wc. in turn, the wc command outputs the number of lines, words, and characters in volcanoes.txt, respectively.

$ cat volcanoes.txt | wc | cat > islands.txt

Multiple |s can be chained together. Here the standard output of cat volcanoes.txt is “piped” to the wc command. The standard output of wc is then “piped” to cat. Finally, the standard output of cat is redirected to islands.txt.

You can view the output data of this chain by typing cat islands.txt.



Let’s try some more redirection commands. In the terminal, type:

cat volcanoes.txt | wc

(Tip: If you are unable to type |, you can find help here.)



cat volcanoes.txt | wc | cat > islands.txt

Use cat to output the contents of islands.txt. Notice that three numbers appear as the output.

Folder Icon

Sign up to start coding

Already have an account?