Using Streams, Pipes, and Redirects in Linux is one of the usual daily tools for sysadmins. I used to be confused about these streams below, but now I’m starting to get more confident about it. I brewed a great Catimor coffee variety before putting together this simple tutorial.
In Linux, every process has three default streams:
- stdin (0) → standard input (keyboard, file, etc.)
- stdout (1) → standard output (screen by default)
- stderr (2) → standard error (screen by default)
Redirect stdout ( > )
Send output to a file (overwrite):
ls > file_list.txtNow the output of ls is saved in file_list.txt.
Append instead of overwrite:
ls >> file_list.txtRedirect stderr ( 2> )
Capture only errors:
ls /fakepath 2> errors.txtSuccess output to the screen.
Errors go to file errors.txt
Redirect stdout and stderr together
ls /etc /fakepath &> output.txtRedirect stdin ( < )
Read from a file instead of typing: (Counts lines from file_list.txt.)
wc -l < file_list.txtPipe Output Between Commands ( | )
Pipes connect stdout of one command to stdin of another. Some examples:
Find number of running SSH processes:
ps aux | grep ssh | wc -lView disk usage sorted by size:
du -sh /var/* | sort -hUse Output of One Command as Arguments (Command Substitution)
echo "Today is $(date)"Make a backup with today’s date:
tar -czf backup-$(date +%F).tar.gz /etcSend Output to Both Screen and File ( tee )
Save command output and still see it:
ls -l /etc | tee etc_list.txtAppend to file:
ls -l /var | tee -a etc_list.txtReal-Life Scenarios for Sysadmins
Debugging logs: (Watch logs live, filter “error”, save to file.)
tail -f /var/log/syslog | grep error | tee errors.logCounting failed SSH login attempts:
grep "Failed password" /var/log/auth.log | wc -lFind biggest files in /var and log them:
du -ah /var | sort -rh | head -n 20 | tee top20files.txtRedirect errors only, while keeping output on screen:
find / -name passwd 2> errors.logAs usual, you can contact me if you have any questions. Also, support my work by shopping one of my T-Shirts or coffee mugs designs. Thanks!

