Menu
Coddy logo textTech

Standard Input

Part of the Fundamentals section of Coddy's Terminal journey — lesson 40 of 82.

The second data stream is standard input, abbreviated as stdin. While standard output is where commands send their results, standard input is where commands receive data.

Many commands can read from a file by taking the filename as an argument:

cat notes.txt
sort names.txt

But you can also redirect a file's contents directly into a command using the < operator:

sort < names.txt

This feeds the contents of names.txt into the sort command through standard input. The result is the same as sort names.txt, but the mechanism is different — the shell handles the file reading instead of the command itself.

You can combine input and output redirection in a single command:

sort < names.txt > sorted_names.txt

This reads from names.txt, sorts the content, and writes the result to sorted_names.txt. Input redirection becomes especially useful when working with commands that expect data from standard input rather than a filename argument.

challenge icon

Challenge

Easy

Use input redirection with the <code>< operator to sort the contents of numbers.txt numerically.

Run a single command that:

  • Redirects numbers.txt into the sort command using <code><
  • Uses the -n flag to sort numerically

Hint: The format is sort -n < filename. The shell reads the file and feeds its contents to the command through standard input.

Cheat sheet

Standard input (stdin) is where commands receive data.

You can redirect a file's contents into a command using the <code>< operator:

sort < names.txt

This feeds the file contents through standard input. The shell handles the file reading instead of the command itself.

You can combine input and output redirection:

sort < names.txt > sorted_names.txt

This reads from names.txt, sorts the content, and writes the result to sorted_names.txt.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals