On the last day, we saw more basic Linux commands which are useful in DevOps. Now today we will move deeper into Linux and will learn about Standard Streams.
Linux Standard Streams ๐จโ๐ป
Standard streams are input and output (I/O) channels, or you could say a bridge between a programme and its environment, in Linux and other generic computer programming languages.
They are also known as input/output(I/O) streams. There are 3 input and output streams in Linux : Standard Input(stdin), Standard Output(stdout) and Standard Error(stderr).
Any command you perform in Linux have to deal with these streams. These stream are also classified by specific numbers called as file descriptors.
- Standard Input(stdin) : 0
- Standard Output(stdout): 1
- Standard Error(stderr): 2
Standard Input(stdin):
Standard input can be in any form in Linux, it can be a file, a command from the keyboard. Normally it is recognised by <
symbol. cat
is best example of stdin.
See, It is taking stdin and generating stdout. This is how these streams work.
Standard Output(stdout):
Stdout can take any form, such as a terminal window, a file, or a response to other commands using pipe. It is represented by >
symbol.
In above process we get the output of ls
command for Desktop folder and redirects it to the file p3.txt
.
Check below image also where we passed output of ls
to cat > p4.txt
using |
symbol.
Standard Error(stderr):
All error messages from a process are sent to standard error(stderr). This is the display screen by default, however it can be redirected just like standard out. However, using ">" to direct the error output to a certain file won't work. Want to see? Try it out.
For redirecting output of stderr we have to use its file descriptor. Now try with 2>
. It won't be blank again.
See, I told you!
Resources ๐
Ending Credits ๐
Okay, so today we looked over to the Linux standard streams and their examples. See you next week with a new Linux topic.