201 β€” Pipes & Redirection

Beginner

Master input/output redirection and piping to chain commands together. Learn to redirect output to files, combine commands with pipes, and handle errors effectively.

Learning Objectives

1
Redirect output to files with > and >>
2
Chain commands together with pipes (|)
3
Handle stderr with 2> and 2>&1
4
Combine multiple commands for powerful workflows
Step 1

Set up practice environment

Create workspace with sample files for practicing redirection.

Commands to Run

cd ~
mkdir redirect-practice && cd redirect-practice
echo 'apple' > fruits.txt
echo 'banana' >> fruits.txt
echo 'cherry' >> fruits.txt
cat fruits.txt

What This Does

> creates new file or overwrites existing. >> appends to file. These are output redirection operators. We're creating a sample file to practice with.

Expected Outcome

fruits.txt created with three lines: apple, banana, cherry. cat shows all three entries.

Pro Tips

  • 1
    > overwrites (creates new or replaces existing)
  • 2
    >> appends (adds to end of file)
  • 3
    Use >> when you don't want to lose existing content
  • 4
    Both create file if it doesn't exist

Common Mistakes to Avoid

  • ⚠️Using > instead of >> and accidentally overwriting important files
  • ⚠️Not realizing > destroys previous content completely
Was this step helpful?

All Steps (0 / 12 completed)