Under normal circumstances every Linux program has three streams opened when it starts; one for input; one for output; and one for printing diagnostic or error messages. These are typically attached to the user's terminal (see man tty(4)) but might instead refer to files or other devices, depending on what the parent process chose to set up.
Redirection is used to redirect the stdout/stdin/stderr.
Operator | Redirect |
---|---|
1> , > |
stdout |
1>> , >> |
Append stdout |
2> , |
stderr |
2>> |
Append stderr |
* 2>&1 , &> |
stderr and stdout |
* Here are two ways on how we would redirect stderr to stdout
command > output_file 2>&1
#or
command &> output_file
Cat the contents of myfirstscript (same as cat myfirstscript
)
$ cat < myfirstscript
Create longlisting with the output of ls -al myfirstscript
$ ls -al myfirstscript > longlisting
Copy the contents of myfirstscript to mynewscript
$ cat < myfirstscript > mynewscript
Pipes are used to give the output of a command as input to another command
$ echo a b c | cut -f 2 -d ' '
b