ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

Bash Shell Scripting Tutorial• 7 min read

I/O Redirection, Pipes & File Descriptors

stdin (0), stdout (1), stderr (2), >, >>, 2>&1, /dev/null, and pipelines |

Linux operates on the Unix philosophy: "Everything is a file." Standard I/O streams can be redirected to disk files or chained across programs using pipes.

The 3 Standard Streams & Redirection

0 (stdin): Standard input (keyboard / stream input).

1 (stdout): Standard output (normal prints).

2 (stderr): Standard error (error messages).

> (Overwrite) vs >> (Append): Redirects stdout to a file.

2>&1: Redirects stderr into stdout so both streams merge into the same destination.

/dev/null: The black hole of Linux. Discards output: command > /dev/null 2>&1.

Pipe (|): Connects stdout of the left program directly to stdin of the right program.

Chaining Pipelines and Silencing Output
# 1. Suppress all output completely
curl -s https://api.codexia.org/health > /dev/null 2>&1

# 2. Pipeline: Find running node processes and count them
ps aux | grep "[n]ode" | wc -l

# 3. Log stdout and stderr into separate files
./deploy.sh > deploy.log 2> deploy_errors.log
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

What does `2>&1` mean in shell redirection?