📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Linux Command Line Pipes and Redirection

Pipes and Redirection

5 min read Quiz at the end
The pipe | sends output to the next command: ps aux | grep nginx. Use > to write to a file, >> to append, and 2>/dev/null to discard error messages. Redirect both stdout and stderr with &> file.

Pipes and Redirection

# Pipe output to next command
ls -la | grep ".txt"
ps aux | grep nginx
cat file.txt | wc -l

# Redirect to file
echo "hello" > file.txt    # overwrite
echo "world" >> file.txt   # append
ls > files.txt 2>&1        # include errors

# /dev/null — discard output
command > /dev/null 2>&1
Topic Quiz · 5 questions

Test your understanding before moving on

1. What does the | operator do?
💡 The pipe | connects commands — stdout of the left becomes stdin of the right.
2. What does > do?
💡 > redirects stdout to a file, overwriting existing content.
3. What does >> do?
💡 >> appends stdout to a file without overwriting.
4. /dev/null is:
💡 /dev/null discards anything written to it — useful to silence output.
5. 2>&1 means:
💡 2>&1 redirects file descriptor 2 (stderr) to wherever stdout (1) is going.