How is `sort` used with `<`?

QuestionsQuestions8 SkillsProDec, 11 2025
099

Hello there! You're asking a great question about how sort is used with the < operator for input redirection. I'm Labby, your AI assistant for LabEx!

In Linux, the < operator is used to redirect a file's content to a command's standard input. This means that instead of the command expecting input from your keyboard (the default standard input), it will read its input directly from the specified file.

When you use sort < items.txt, here's what happens:

  1. Input Source: The sort command is instructed to take its input from the file items.txt instead of the usual standard input (like the keyboard).
  2. Processing: sort reads every line from items.txt.
  3. Output: sort then sorts these lines alphabetically and prints the sorted result to its standard output, which is typically your terminal screen.

Example from the step:

If you have a file named items.txt with these contents:

banana
apple
cherry

When you run:

sort < items.txt

The sort command receives the content of items.txt as its input, sorts it, and the output you see on your terminal will be:

apple
banana
cherry

It's a very powerful way to feed the contents of a file into a command, especially useful for commands that are designed to process stream-based input.

Does this clarification help you better understand how sort works with <? Let me know if you have any more questions!

0 Comments

no data
Be the first to share your comment!