bash pipes redirection command-line

Pipes and Redirection

The pipe `|` sends one command's output to another command's input. Redirection `>` sends output to a file.

This is the Unix philosophy in action: small tools that do one thing well, chained together.

bash
# Pipe: send output to another command
cat file.txt | grep "error" | wc -l

# Redirect output to a file (overwrites)
echo "hello" > file.txt

# Append to a file
echo "world" >> file.txt

# Redirect errors separately
command 2> errors.log

# Redirect both stdout and stderr
command > output.log 2>&1
Command Line Confidence

This tip is from

Command Line Confidence

100 more tips like this one.

Get the Book