0
0
Linux CLIscripting~3 mins

Why stdin redirection (<) in Linux CLI? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

Discover how a simple symbol can save you hours of tedious typing!

The Scenario

Imagine you have a long list of names saved in a file, and you want to run a command that processes each name one by one. Without redirection, you would have to type or copy-paste each name manually into the command prompt.

The Problem

This manual typing is slow and tiring. It's easy to make mistakes like typos or missing lines. Also, repeating the same command for many inputs wastes time and energy.

The Solution

Using stdin redirection with the < symbol, you can feed the contents of a file directly into a command as if you typed it yourself. This saves time, reduces errors, and automates the process smoothly.

Before vs After
Before
command
name1
command
name2
command
name3
After
command < names.txt
What It Enables

This lets you easily automate commands that need input, making your work faster and more reliable.

Real Life Example

For example, if you have a file with a list of email addresses and want to send a welcome message using a command-line tool, you can redirect the file as input instead of typing each email manually.

Key Takeaways

Manual input is slow and error-prone.

Stdin redirection feeds file content directly to commands.

This makes automation simple and efficient.