File descriptors - GradedJestRisk/linux-training GitHub Wiki

File descriptors

For definitions, see https://github.com/GradedJestRisk/linux-training/wiki/bash#file-descriptors

file descriptors

  • input : 0 (STDIN)
  • output :
    • standard : 1 (STDOUT)
    • error: 2 (STDERR)

stdin, stdout, and stderr

  • are streams
  • attached to file descriptors 0, 1, and 2 respectively
  • of a process

https://unix.stackexchange.com/questions/400849/echo-or-print-dev-stdin-dev-stdout-dev-stderr

Combine

Copy standard input to standard output : cat

Output (concatenate) file then standard input : cat /path/to/file -

You can pipe between commands using | (pipe), eg. a | b

You can redirect between commands using > (angle bracket), eg. a > b

You can append to a file using >> (shif-right), eg. a > b

tee writes (buffered):

  • from stdin ;
  • to stdout and files.

'sponge' writes (unbuffered) :

  • from stdin ;
  • to a file (only); (without errors, no output)