Note that this site is in currently in version 1.0.0-alpha.   Some functionality may be limited.

9. Pipes

So far, you’ve learned a number of commands and one special symbol, the > or redirect. Now we’re going to learn another, the | or “pipe.” Pipes let you take the output of one command and use it as the input for another. Pipes diagram Let’s start with a simple example:

$ echo "Hello from the command line" | wc -w
5

Pipes diagram In this example, we take the output of the echo command (“Hello from the command line”) and pipe it to the wc or word count command, adding a flag -w for number of words. The result is the number of words in the text that we entered. Flags marked with hyphens, such as -l or -m, indicate options which belong to specific commands. Let’s try another. What if we wanted to put the commands in our cheat sheet in alphabetical order? Use pwd and cd to make sure you’re in the folder with your cheat sheet. Then try:

$ cat cheat-sheet.txt | sort

You should see the contents of the cheat sheet file with each line rearranged in alphabetical order. If you wanted to save this output, you could use a > to print the output to a file, like this:

$ cat cheat-sheet.txt | sort > new-cheat-sheet.txt

Challenges for lesson 9

Questions

Try again!

What do pipes allow you to do?

(Select all that apply)

Workshop overall progress