Redirecting -piping with “|’

Hi everyone,

Redirection command line exercise, page 6, piping.
Can anyone explain | to me? I don’t get the purpose of it or what it does;

Ex: $ cat volcanoes.txt | wc

Thanks

You’re using cat to read the file and streaming a copy of the contents of that file to standard output, typically that would be text in your terminal. By using pipe you’re connecting that output stream to the input of the wc command.

We could for example conCATenate several files and send the combined output to the input of the wc command cat volcanoes.txt file2.txt | wc (giving us a total).

In this short example it’s not really necessary and wc can accept several input files (though it processes them differently in this case) but I think it’s just used as an example. If you want more info have a web search for pipes as there’s plenty of descriptions and quality examples available online.

1 Like

Thank you! I will take a look at more info as well.

1 Like