Script Valley
Linux Basics Complete Course: From Beginner to System Administrator
Module 3: File Management CommandsLesson 3.3

Input/Output Redirection and Pipes | Linux Terminal Commands

stdin, stdout, stderr, redirection, pipes, |, >, >>, 2>, tee

Input/Output Redirection and Pipes

One of the most powerful features of the Linux command line is the ability to redirect input and output and to chain commands together using pipes. These capabilities allow you to build complex data-processing workflows from simple commands.

Standard Input, Output, and Error

Every Linux process has three standard data streams: stdin (standard input, file descriptor 0), stdout (standard output, file descriptor 1), and stderr (standard error, file descriptor 2). By default, stdin reads from the keyboard and stdout and stderr print to the terminal.

Output Redirection

The greater-than symbol (>) redirects stdout to a file, overwriting it. The double greater-than (>>) appends to a file without overwriting. The 2> operator redirects stderr to a file.

ls -la > directory-listing.txt
echo "New entry" >> log.txt
find / -name "*.conf" 2> /dev/null
command > output.txt 2>&1

Redirecting stderr to /dev/null discards error messages. The 2>&1 syntax redirects stderr to the same place as stdout, combining both streams.

Pipes

The pipe operator (|) connects the stdout of one command to the stdin of the next. This allows you to chain commands to transform and filter data step by step.

ls -la | grep ".txt"
cat /etc/passwd | grep "alice"
ps aux | grep nginx
history | tail -20 | grep "apt"

Pipes are the foundation of the Linux philosophy of combining small, focused tools into powerful workflows.

The tee Command

The tee command reads from stdin and writes to both stdout and a file simultaneously. This is useful when you want to see command output in the terminal and save it to a file at the same time.

ls -la | tee listing.txt
ping google.com | tee ping-log.txt

Practical Pipe Examples

Combining grep, sort, uniq, and wc creates powerful one-line data analysis commands that would otherwise require a full script in another language.

cat /var/log/syslog | grep "error" | wc -l
du -sh /var/* | sort -h | tail -10
cat /etc/passwd | cut -d: -f1 | sort

These patterns represent the core of the Linux command line philosophy and are used constantly by system administrators and developers working in Linux environments.