Search The Site

Linux Standard Input (stdin) Explained

There are a host of commands that will accept input from standard input, also known as stdin for short. By default, standard input reads information from your keyboard, but just like standard output, it can be redirected in various ways.

We can use the less-than symbol to redirect the standard input to be from a file rather than a keyboard.

You use input redirection using the less-than symbol and it is usually used with a program which accepts user input from the keyboard. When the notation less-than filename is added to the end of a command, the input of the command is read from the specified file name. The less-than symbol is known as the input redirection operator. Only commands that normally take their input from the keyboard can have their input redirected.

for example in order to send the file happy_birthday.txt as a message to a user named slatz with the mail command, type the following:

mail slatz < happy_birthday.txt 

In this case the results aren't displayed on your screen. Because the output is redirected, the results are written to a file called happy_birthday.txt