Archive for the tag 'descriptors'

SBDavid

Use of file descriptors

Use of file descriptors

There are three types of I/O, which each have their own identifier, called a file descriptor:

standard input: 0

standard output: 1

standard error: 2

In the following descriptions, if the file descriptor number is omitted, and the first character of the redirection operator is , the redirection refers to the standard output (file descriptor 1).

Some practical examples will make this more clear:

ls > dirlist 2>&1

Will direct both standard output and standard error to the file dirlist, while the command

ls 2>&1 > dirlist

Will only direct standard output to dirlist. This can be a useful option for programmers.

ampersand is used to run a process in the background. Here, it merely serves as an indication that the number that follows is not a file name, but rather a location that the data stream is pointed to.