Every Linux program interacts with three core data streams:
stdout
)ls -l /usr/bin > ls-output.txt
This redirects output to a file instead of displaying it in the terminal.
stderr
)ls -l /bin/usr 2> ls-error.txt
Error messages are saved to a separate file, while standard output remains visible.
stdout
and stderr
ls -l /bin/usr > ls-output.txt 2>&1
ls -l /bin/usr &> ls-output.txt
ls -l /usr/bin >> ls-output.txt
Appends new data to the existing file content.
/dev/null
ls -l /bin/usr 2> /dev/null
Redirects error messages to the "bit bucket" where they are ignored.
cat
with stdin
cat filename
cat > lazy_dog.txt
Ends input with Ctrl+D.
cat < lazy_dog.txt
|
ls -l /usr/bin | less
Passes output of one command as input to another.
ls /bin /usr/bin | sort | uniq | less
ls /bin /usr/bin | sort | uniq -d | less
wc
ls /bin /usr/bin | sort | uniq | wc -l
grep
ls /bin /usr/bin | sort | uniq | grep zip
Options: -i
(ignore case), -v
(invert match)
head
and tail
head -n 5 ls-output.txt
tail -n 5 ls-output.txt
tail -f
:tail -f /var/log/messages
tee
ls /usr/bin | tee ls.txt | grep zip
Saves full list to file while allowing filtered output downstream.
By mastering Linux I/O streams and pipeline mechanics, users can redirect output, control errors, filter results, and structure complex data-processing workflows. Tools like sort
, wc
, grep
, tee
, and /dev/null
empower users to manage data like pros within the shell environment.