Linux command line skills are in demand in virtually every IT field today. Therefore, it's best to begin learning the profession by familiarizing yourself with this OS. This will likely significantly simplify your studies and future work. Today, we'll teach you how to replace keyboard input with text from a file—this is part of the Linux Fundamentals course in Shymkent . It's also a must-read for anyone looking to become an IT specialist in Kazakhstan in 2023.
Replacing keyboard input with text from a file, Linux Basics Course Shymkent
First, let's understand how the operating system interprets keyboard input. This topic is included in any basic Linux course in Shymkent . It's also a must-read for LPIC-1 certification exams. UNIX-like operating systems have three main standard text streams:
- stdin — standard input (stream 0);
- stdout — standard output (stream 1);
- stderr — standard error output (stream 2).
In our previous articles, we've already demonstrated how to redirect stream 1 (standard input) to a file. We also provided examples of typical operations that might be needed in your work. Now it's time to try redirecting stream 0—standard input. To do this, use the less-than symbol (" < ").
To begin, let's create a file using the cat command , saving text to it using the standard output redirection operator, " > ." Then, enter a random combination of numbers, each time starting on a new line. Press Ctrl + D to finish entering the text and complete the operation. Now you have a file containing text consisting of numbers, one per line. Let's try redirecting its contents to another command, such as sort.
The sort utility is a command-line tool for UNIX-like systems designed for sorting text. Enter the sort command in the command line and add the standard input redirection symbol " < ." Immediately after that, add the name of the file you previously created in the current working directory.
If you created a file in a different directory, you must either change the current working directory or specify the entire path to the file. As a result, we see that the sort command accepted the text from the file as an argument and obediently output the sorted contents to the command line. Enroll in our Red Hat Linux courses in Shymkent to become an IT specialist in Kazakhstan.
Why Replace Keyboard Input with Text from a File in Linux
First of all, such redirection allows you not to enter the text manually each time. And just save it to a file to conduct regular checks of certain parameters easier and faster. That is, enter only the command you are interested in and the name of the file from which the text should be taken. At the same time, this file is not executable, that is, it does not fall under the prohibitions and restrictions on the use of scripts.
Of course, many commands can simply accept a file path instead of an argument. And you don't have to use the redirection symbol. That is, with the sort utility, you don't have to use the "<" sign. However, in some cases, the ability to redirect input can be indispensable. We'll talk about this in more detail in our tutorials.
It's worth noting that the SEDICOMM University platform offers a full Linux lecture course in Shymkent . It will help you become an IT specialist as quickly as possible, in about six months. And find a high-paying job that allows you to be resilient to any crisis. Most importantly, don't waste your time; study and learn something new!
SEDICOMM University Team : Cisco Academy , Linux Professional Institute , Python Institute.

