Blackhole in Linux /dev/null

So here’s the thing…

Ever since I started using Linux, I kept seeing people write stuff like > /dev/null in their commands.
At first, I just copied it without thinking. But today I finally decided to figure out what the hell it actually does. It’s actually a black hole, a vacuum, a void where Goliath lives (from the Loki series).

What is /dev/null?

/dev/null is actually a Linux file that sucks up anything fed to it. stdout is consumed. If you check /dev/null, it’s actually a valid file. Any file redirection into /dev/null will be discarded into the vacuum. Using a file descriptor like 2, we can throw stderr to /dev/null.

command > /dev/null 2>&1

It’s not like you’re writing it to storage and then erasing it. When we try to write something to disk, the OS kernel has the authority to decide if that file is going to the disk — or, like with the null device, it just discards it before it even reaches the disk.

Basically, the data isn’t stored and then discarded — it’s just discarded.

During my research, I found this funny website and thought of sharing it with you guys: https://devnull-as-a-service.com/

What purpose does /dev/null serve?

The use case is quite simple. It just suppresses the output. Say you are writing a bash script and you don’t want the stdout to be printed — just throw it to /dev/null. Make the terminal clean.

What I found out

This is where I explain it in my words. No fancy textbook stuff.

  • Turns out /dev/null is basically a black hole.
  • Anything you send there just disappears.
  • Super useful when you don’t care about output and want to keep your terminal clean.