FAQ: Redirection - |

This community-built FAQ covers the “|” exercise from the lesson “Redirection”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Learn the Command Line

FAQs on the exercise |

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hi!
I have a question concerning my comprehension of the | effect here…
cat volcanos.txt | wc outputs the number of lines, words and characters in volcanoes.txt (I understand that). cat volcanoes.txt | wc | cat > islands.txt (from what I understand, cat islands.txt output became volcanoes.txt | wc output).
Is that correct, and especially is it a good way to say it? - sorry I try to understand by verbelazing the concept.
Thank you for your answer.
FL

I think you are right.

How I would phrase it is:

  • cat volcanoes.txt | wc : the content of volcanoes.txt is provided to the command wc by the pipe, which provides the number of lines, words and characters of the provided content. Other way more complicated to say it:
    • “stdin” of cat is the file volcanoes.txt.
    • “stdout” of cat volcanoes.txt is the content of the file volcanoes.txt
    • “stdin” of wc is the “stdout” of cat volcanoes.txt (because of the pipe).
    • “stdout” of cat volcanos.txt | wc is the number of lines, words and characters of the content of the file volcanoes.txt.
  • cat volcanoes.txt | wc | cat > islands.txt : the “stdout” of cat volcanos.txt | wc is the new input of the second cat wich is then redirected to the file “island.txt” through the > command (i.e. the content of “island.txt” is replaced by the output of the second cat, here the number of lines, words and characters of the content of the file volcanoes.txt)

Why to use the second cat in cat volcanoes.txt | wc | cat > islands.txt?

Why not simply put cat volcanoes.txt | wc > islands.txt?

Hi,

Thank you for your answer. I am not familiar yet with all that but I think you answered my question.
I understand but it is still not “natural” for me, like a language that I am learning (that is what I am doing actually) but do not master at all yet, I am far from fluent.
And concerning your “Why” in your second message it is simply because the exercice explained the redirections this way.
Thank you again :slight_smile:

I am questioning the same thing. Anyone?