---
title: "3 File Descriptors in Unix Operating System: What They Mean"
description: "How to use file descriptors in Unix is explained in this post. Unix supports three types. Here is an example that shows how it works."
url: https://srinimf.com/2021/10/11/3-file-descriptors-in-unix-operating-system-what-they-mean/
date: 2021-10-11
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2021/10/pexels-photo-3184295.jpeg?fit=1880%2C1253&ssl=1
categories: ["Shell scripts"]
type: post
lang: en
---

# 3 File Descriptors in Unix Operating System: What They Mean

Unix [operating system](https://srinimf.com/2019/03/02/9-linux-tricky-points-every-user-must-know/) supports *three file descriptors*. Those are stdin(0), stdout(1) and stderr(2). Here is an example that shows [how to](https://srinimf.com/2021/10/18/heres-the-top-command-to-change-shells-in-ubuntu-quickly/) use them.

File descriptor means standard file ports. Precisely, you can redirect your script command result or you can get input from terminal to script. Input & Output – These two functions you can do with the file descriptors.

## File Descriptors

```
0 - stdin  - Keyboard
1 - stdout - display
2 - stderr - display
```

### Details of File Descriptors

| stdin | Standard input |
| --- | --- |
| stdout | Standard output |
| stderr | Standard error |

#### [What is](https://srinimf.com/2013/01/02/oracle-lpar/) a bit bucket in Unix?

It’s just a null file. It deletes data immediately after it receives, and sets the file status to end-of-file. Here is the directory of Bit Bucket.

#### Bit bucket

/dev/null

- The Easiest 5-Step Anti-Aging Routine for Glowing Skin

### How to work with File Descriptors

Firstly, send error messages to stderr (2), then stderr(2) to stdout(1). The ‘>&’ just copy the messages present in stderr to stdout. The ‘$?’ tells the status of the previously executed command. Here is more on File Descriptors.

In myfunction1, added a command. I am checking the command status by using $?. After closing the curling bracket, I have given myfunction1 – why means this is how we call the function in the script.

```
#!/usr/bin/bash
myfunction1()
{
ls -0 > /dev/null 2>&1
echo "$?"
}
myfunction1
```

### Video – How bit bucket discards Error Messages

The status code is ‘2’. That means only you will get status codes, and you’ll not get an error message, since it’s discarded.

### Video – How to Display Error Messages

**Modified Script**

Here, I have used the local directory path, instead of the bit bucket directory. So you can see error messages and status codes as well.

```
#!/usr/bin/bash
myfunction1()
{
ls -0 > /tmp/dev/null 2>&1
echo "$?"
}
myfunction1
```

Related Posts

- [How to Call a Shell Script from Another Script](https://srinimf.com/2021/11/01/heres-the-real-reason-to-include-script-in-other-script/)DateNovember 1, 2021
- [JCL ‘BPXBATCH’ Utility to run UNIX commands](https://srinimf.com/2015/11/11/the-bpxbatch-utility-to-unix-commands-through-jcl/)DateNovember 11, 2015
- [Here’re Top Linux [UNIX] File Commands (Part 1)](https://srinimf.com/2014/06/30/pro-unix-commands/)DateJune 30, 2014

Get new content delivered directly to your inbox.

Type your email…

Sign up

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2021%2F10%2F11%2F3-file-descriptors-in-unix-operating-system-what-they-mean%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2021%2F10%2Fpexels-photo-3184295.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=3%20File%20Descriptors%20in%20Unix%20Operating%20System%3A%20What%20They%20Mean)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2021/10/11/3-file-descriptors-in-unix-operating-system-what-they-mean/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2021/10/11/3-file-descriptors-in-unix-operating-system-what-they-mean/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2021/10/11/3-file-descriptors-in-unix-operating-system-what-they-mean/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2021/10/11/3-file-descriptors-in-unix-operating-system-what-they-mean/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%203%20File%20Descriptors%20in%20Unix%20Operating%20System%3A%20What%20They%20Mean&body=https%3A%2F%2Fsrinimf.com%2F2021%2F10%2F11%2F3-file-descriptors-in-unix-operating-system-what-they-mean%2F&share=email)
-

### Like this:

Like Loading…
