> ## Content Index
> Fetch the complete content index at: https://linuxhandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# What is /dev/null in Linux?
- URL: https://linuxhandbook.com/dev-null/
- Published: 2023-01-23T12:12:47.000Z
- Updated: 2023-10-19T14:58:47.000Z
- Description: /dev/null is the blackhole equivalent of Linux systems. What is it and why it used?
- Author: Sagar Sharma
- Tags: Explain

If you have been using Linux user for a while, you must have come across the term /dev/null, at least in memes.

`/dev` is a directory where most of the external peripherals are mounted such as the disk drives. 

But this /dev/null file is special due to its characteristics, which I will discuss in this guide.

## What is /dev/null?

It is a virtual file with a unique way of dealing with files. Anything written on /dev/null will disappear and can not be recovered. A command is supposed to generate huge output? [Redirect it to /dev/null](https://linuxhandbook.com/redirect-dev-null/) and the output will not be seen anywhere in the system, not even in the /tmp. This is why it is called the black hole of Linux.

Let me share a quick example here. 

Here, [I redirected my standard output](https://linuxhandbook.com/redirection-linux/) to the `/dev/null`:

```
echo "Linuxhandbook" > /dev/null
```

![rediredt standard output in linux](https://linuxhandbook.com/content/images/2023/01/rediredt-standard-output-in-linux.png)

And as you can see, when I used [the cat command](https://linuxhandbook.com/cat-command/) to print the contents of `/dev/null`, it showed nothing.

Now, let's dive deep by learning the file properties of `/dev/null`.

## File properties of /dev/null

For better readability, I will be using[ the stat command to know the status of the filesystem.](https://linuxhandbook.com/stat-command/)

```
stat /dev/null
```

![know the status of filesystem using the stat command](https://linuxhandbook.com/content/images/2023/01/know-the-status-of-filesystem-using-the-stat-command.png)

And it explains a lot. 

- It is empty
- The creation date is the same as my last boot
- The file's UID and GID are 0
- And every user is allowed to read and write on `/dev/null`
- It is a character device file which means it will act like an unbuffed device and can accept data streams

So you can send any number of files to the `/dev/null`, it can't be filled or won't increase in size.

💡

The /dev/null acts as a file and as a result, you can not use the mv command to remove or dump directories with dev/null.

## Use of /dev/null in Linux

As I mentioned earlier, it is a black hole and whatever is sent there, can not be recovered. 

One of the most common use of /dev/null is to redirect either error or output of a command to this file.

Imagine a command runs for some time and it generates both standard output and errors. If you are only interested in reading the error, you can redirect the output to /dev/null so it only displays the errors.

```
command 1> /dev/null

```

Similarly, if you only want to see the standard output, not the errors, you can redirect the errors to the /dev/null.

```
command 2> /dev/null

```

You can send both standard output and the error to /dev/null. This will run the command but won't show anything on the screen.

```
command 2>&1 /dev/null
```

If all those 2>&1 stuff look like algebra to you, I highly recommend reading on [stdout, stdin and stderr](https://linuxhandbook.com/redirection-linux/) redirection in this article.

[Input Output & Error Redirection in Linux \[Beginner’s Guide\]Redirection is an essential concept in Linux. Learn how to use stdin, stdout, stderr and pipe redirection in Linux command line.![](https://linuxhandbook.com/content/images/size/w256h256/2021/08/Linux-Handbook-New-Logo.png)Linux HandbookAbhishek Prakash![](https://linuxhandbook.com/content/images/2020/06/Linux-redirection.png)](https://linuxhandbook.com/redirection-linux/)

Let me so a silly but simple example.

Here, I have used two commands `ls` and `apt update` in which the command to update repositories (apt update) will require superuser privileges.

And in the ideal case, it should get me the following output:

```
ls && apt update
```

![execute two commands at once using the & operator in linux](https://linuxhandbook.com/content/images/2023/01/execute-two-commands-at-once-using-the---operator-in-linux.png)

Now, I will redirect the error part to the /dev/null:

```
ls && apt update 2> /dev/null
```

![redirect output to /dev/null in linux](https://linuxhandbook.com/content/images/2023/01/redirect-output-to-dev-null-in-linux.png)

And as you can see, the error part of the output is no longer displayed. 

## There are more dev files...

The /dev/null is not the only special device file. There is /dev/zero for creating files filled with zeroes or [/dev/random](https://linuxhandbook.com/dev-random-urandom/) that is used for generating random numbers.

[What is /dev/zero in Linux?One of the special device files in Linux, /dev/zero is used for creating files filled with zeroes.![](https://linuxhandbook.com/content/images/size/w256h256/2021/08/Linux-Handbook-New-Logo.png)Linux HandbookSagar Sharma![](https://linuxhandbook.com/content/images/2022/12/dev-zero-linux.png)](https://linuxhandbook.com/dev-zero/)

And to end this article, I'll share a cool /dev/null meme with you 😎

![/dev/null Linux meme](https://linuxhandbook.com/content/images/2023/01/dev-null-meme.jpg)