Redirect input and output
You can redirect the input to a program from a file. You can also redirect the output of a program to a file. Redirections are done using symbols after the command. For example, to redirect the output of the ls command to the file ls_output.txt, we can use the following command:
Note that the ls command didn’t output anything to the terminal. This is because we have redirected the output from the terminal to the file using the > operator. We’ve then displayed the content of the ls_output.txt file using the cat command.
Here is a list of all redirection symbols:
Here are a couple of examples.
To append the standard output to the file, use the >> operator:
In the example above we have added the current date to the end of the ls_output.txt file.
For an example of the input redirection, we will use the mail command. This command takes the content of a file as standard input. For example, to mail the content of the file ls_output.txt to the user bob, we can use the following command: