Standard Streams 2
PIPE
In UNIX, pipe operation is to direct a standard output of a command to be the standard input of another command. The standard output of a program can be redirected to another program as a standard input, the standard error can only be redirected to a file.The "bc" program receives input from the keyboard. In processing this input, the generated errors are written to the screen via the standard error channel, and the results generated during the input process are also given to a pipeline instead of the standard output device monitor. The standard output of the "bc" output from the pipeline is given as standard input to the command "wc -l". "wc -l" processes the standard input from the pipeline and sends the errors to the screen via the standard error channel, while the normal results are sent to the same screen via the standard output channel. In this way, UNIX commands can be connected to the end-point to perform very meaningful and challenging tasks easily.Example usage of pipe:
Example commands using pipe (|):
program1 | program2 : Standard output of the program1 is redirected to program2 using pipe.
program1 2> errors.txt | program2 : Standard output of the program1 is redirected to program2 using pipe. Also standard error of program1 is redirected to a file named errors.txt
The operators "<", ">", ">>", "2>", "2>&1" are used to direct input and output.
These operators are placed between a command set (command and parameters) and a file, and input and output are directed.
In output directories made using ">", the output file overwrites the file if it already exists. The ">>" operator can be used to prevent this and add it to the file.
If the file to which the output is directed does not exist, it is created automatically.
command > file.txt 2>&1 : both standard error and standard output are merged into the "file.txt" file.
"tee" Command
The "tee" command copies the standard input as if it were a standard output, and at the same time writes the standard input to the specified file.In general, it is used to transfer the intermediate results of the commands connected to the end via the boring method.
The "tee" command overwrites the specified file under normal circumstances. However, if the contents of the file need to be lost, and the backend is desired, the "tee" command should be used with the "-a" option in the form "tee -a file".
To read my previous article: Standard Streams 1