as a linux user you will need to understand this concept at some point stdin, stdout, stderr, most cli tools you would use as a linux user will make use of this.

  • 0 represents Standard Input
  • 1 represents Standard Output
  • 2 represents Standard Error

When using CLI tools you can redirect the output using the greater than symbol

like this

find > output

you can also be specific, in this example we are redirecting all the errors to /dev/null

find 2> /dev/null

Code Example

you can use this code example to get an uderstanding how STDIN, STDOUT, STDERR works, this program might not work on windows or mac since we are using the linux write syscall.

1#include <unistd.h>
2int main(){
3  write(0,"From STDIN\n",12);
4  write(1,"From STDOUT\n",13);
5  write(2,"From STDERR\n",13);
6}

to compile

gcc main.c

to output only stdout

here STDIN and STDERR is getting redirected to /dev/null and only STDOUT in being outputed

./a.out 2> /dev/null 0> /dev/null