File Descriptors

When you issue any command, three files are opened and associated with that command. In the shell, each of these files is represented by a small integer called a file descriptor. A file descriptor is a mechanism by which you can associate a number with a filename and then use that number to read and write from the file. File descriptors are often referred to as file handles.

The three files opened for each command along with their corresponding file descriptors are

  • Standard Input (STDIN), 0

  • Standard Output (STDOUT), 1

  • Standard Error (STDERR), 2

The integer following each of these files is its file descriptor. Usually, these files are associated with the user's terminal, but they can be redirected into other files. In the previous ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.