student@ubuntu:~$
shell 3/5 30 XP

Redirection and Pipes

0%

Quick Reference

Redirection operators:

Operator Effect
> file Redirect stdout to file (overwrite)
>> file Redirect stdout to file (append)
< file Redirect file to stdin
2> file Redirect stderr to file
2>&1 Redirect stderr to stdout
&> file Redirect both stdout and stderr (bash)

Pipeline pattern:

producer | filter | filter | consumer
# Example:
cat access.log | grep 404 | sort | uniq -c | sort -rn | head

Common Pitfalls

  • Order matters with 2>&1cmd > file 2>&1 works (stderr follows stdout to file). cmd 2>&1 > file doesn’t (stderr goes to terminal).
  • Overwriting with >cmd > important.txt destroys existing contents. Use >> to append.
  • Broken pipe – If a downstream command exits early (like head), upstream gets SIGPIPE. Usually harmless but can cause confusing error messages.

Unlocks

Complete this skill to see what it unlocks.