Redirection and pipes

Video may be blocked due to browser extensions. In the article you will find a solution to this problem.

Important notes

  1. Redirections operate on standard input and output (STDIN, STDOUT). Read more about standard input/ouput here or just google "unix stdin stdout".
  2. In addition to >, which directs an output into a file, there is also >>, which appends the file, or, in other words, adds stuff to the end of the file.
  3. wc is used to count characters, words and lines. wc -l counts lines only.
  4. uniq eliminates repeated lines (outputs the file with adjacent identical lines collapsed to one). It only works when repeated lines come together in a single continuous block. Example: sort file.txt | uniq

Lesson notes

  • > to redirect an output into a file (e.g. ls /var/logs > logs.txt)
  • < to redirect a file (e.g. sort < names.txt)
  • | to connect two commands with a pipe (e.g. ls | grep)
We teach programming in a new way. Check out "Intro to Programming" course.


Learn about why Hexlet is so good →