Linux Input Output Redirection

Standard Input [stdin]

Normally in linux the standard input is the console prompt, however this can change and set to be a file for example within the next command

$ process_that_require_a_file_as_input < file_required_by_process.txt

In this case the standard input of input was defined to be a file instead of the command prompt

Standard output [stdout]

Also the standard output in linux is the console, which generarly displays the results from an executed command

$ date
Sun Apr 16 08:53:44 EDT 2017

We can redirect the standard output using the placeholder >

Sample 

$ date > date.txt

Standard error [stderr]

This stream displays errors and it could be redirected using the placeholder 2>

$ comamnd_that_fails 2> failure.txt

​The &> placeholder

This symbol represent the standard output and the standard err, meaning that if we want to redirect both outputs we can do something like this

$ command_that_runs_and_have_sime_fails &> log.txt

​This command will redirect either normal output and error output to the file log.txt

The Pipe |

This symbol is useful in order to send the output of a command and put it as input for another command

$ ps auz | grep process_name

​This command will first execute the ps command and pass the output to the command grep in order to check for a process called process_name

The Append >>

This symbol is used to append data to a file

$ echo "this data will be appended " >> text.log

​The Add >

This symbol is used to add data to a file, it will overwrite what was written before, use with caution

$ echo "this data will be add and will overwrite what was written before " > text.log