Hey everyone 👋
When I first started learning the command line, I thought it was just a place to type a bunch of commands and watch stuff fly across the screen. But then I discovered something called redirection — and suddenly, the terminal became a toolbox, not just a text box.
Whether you're managing logs, cleaning up files, or piping data between tools — redirection is how pros turn one-liner commands into power moves.
Let me explain it the way I wish someone had explained it to me 👇
🔁 Think of Redirection Like Plumbing for Text
Imagine you're in a kitchen. You've got:
- a sink (your command),
- a pipe (the redirection symbol),
- and a bucket (a file or the next command).
Normally, a command sends output to your screen (stdout). But with redirection, you can reroute that output into a file, another command, or even pull input from a file.
⚙️ Core Redirection Symbols
| Symbol | What It Does |
|---|---|
> |
Sends output to a file (overwrites) |
>> |
Sends output to a file (appends) |
< |
Sends a file as input to a command |
✍️ Example: Output to File
echo "Hello World" > hello.txt
✅ Creates a file with your message.
echo "Welcome back!" >> hello.txt
✅ Appends new content to the existing file.
📥 < — Feed Commands from a File
Instead of typing everything manually, let a file do the talking:
cat < greetings.txt
🗣️ Translation: “Hey cat, read from this file instead of my keyboard.”
🔗 | — The Game-Changer: Piping Commands Together
Want to clean up a list of names?
cat names.txt | sort | uniq > clean-names.txt
Each command passes its result to the next — like a conveyor belt on an assembly line.
🔍 Combine with Power Commands
These tools pair beautifully with redirection:
-
sort: Alphabetizes your data -
uniq: Removes adjacent duplicates -
grep: Searches for patterns -
sed: Replaces or transforms text
Example: Filter and Clean Error Logs
grep -i "error" logs.txt | sort | uniq > error-summary.txt
✅ Now you’ve got a clean, sorted list of all errors — ready for review.
🧠 Pro Tip: Not All Redirection Changes Files
sed 's/snow/rain/g' weather.txt
This shows you the result, but the file stays unchanged.
To update the file in-place:
sed -i 's/snow/rain/g' weather.txt
📝 The -i flag is your "make it real" switch.
💡 Why Redirection Matters (Even If You're Not a Linux Wizard Yet)
You’ll use redirection for:
✅ Cleaning up messy data
✅ Logging output from a long script
✅ Building automations for daily tasks
✅ Learning how DevOps pipelines work behind the scenes
Redirection gives you super control over what your commands do and where your data goes.
🧩 Final Thoughts
When I first saw > and | in tutorials, I’d skip past them — they looked cryptic.
But once you start using them, you realize they’re not just shortcuts — they’re infrastructure for your workflows.
Redirection starts off small… but ends up everywhere.
If you're learning the terminal or scripting your first automation, I’d love to hear how you're using redirection (or struggling with it — I’ve been there too).
💬 Drop a comment or hit me up on LinkedIn — let’s keep building our command-line superpowers together! 💻⚡
Top comments (0)