Bash & Linux·Bash from first command to automation

Pipes and redirection

Connect commands and send output where you want it.

Beginner 13 min read Lesson 4 of 300 Challenge included
What you will be able to do
  • Use | to chain commands.
  • Use > to overwrite and >> to append.
  • Use 2> for errors and 2>&1 to merge streams.
  • Use tee to write and display at once.

In plain English

A pipe sends stdout of one command to stdin of another. Redirection writes stdout to a file with > (overwrite) or >> (append), and 2> captures stderr. Small commands composed with pipes solve big problems.

terminalTerminal
ls -la | grep ".md" | wc -l
echo "build started" >> build.log
npm run build 2>&1 | tee build.log
Your turn

Count Markdown files

Easy

Count the .md files in the current directory using a pipe.

BASH · starter
ls
Check your understanding before moving on.
Knowledge checkQuestion 1

Which operator appends output to a file?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Text processing
Lesson 4 of 300 · 0% of course