Register to get access to free programming courses with interactive exercises

Redirection and pipes Basics of Bash

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)

Are there any more questions? Ask them in the Discussion section.

The Hexlet support team or other students will answer you.

About Hexlet learning process

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.bookmate">Bookmate</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.healthsamurai">Healthsamurai</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.dualboot">Dualboot</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.abbyy">Abbyy</span>

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending this form, you agree to our Personal Policy and Service Conditions