Image of a terminalImage: Gemini
Image of a terminal

This blog, and its several fans (typically more than two but fewer than “many”, which feels about right), is named after /dev/null. Why? Because /dev/null is a black hole for reading and writing, a place where things go to disappear forever. That is exactly how I feel when writing about things like shortcomings in email security policies. Screaming into the void /dev/null.

But let’s put that aside for now and take a brief moment to get to know our friend /dev/null.

What Is /dev/null?

/dev/null is a file on Unix-like systems that discards anything you write to it. Technically, it’s a device file, which is a special kind of file that provides an interface to hardware or virtual devices. Device files allow software programs to interact with hardware (e.g., hard drives, printers) as if they were ordinary files. Usually, this works by the device file calling a device driver in the kernel that writes to a physical device and returns a status code or some other information.

/dev/null is its own special kind of device file. When you write to /dev/null, instead of writing that data to a hard disk (or somewhere else), it simply discards the data. You can even take a look at the write_null function in the Linux source code, which is used to implement /dev/null. You can see that it simply discards the input and returns a success message.

But what’s the point? /dev/null was created way back in the early days of Unix to give programs a safe place to dump output they didn’t care about, and it’s still used today for the same reason. Instead of spamming the screen or filling up storage with temporary logs, you can redirect anything you want to ignore into /dev/null.

/dev/null And Friends

/dev/null is not alone in this world. It has some notable friends:

  • /dev/zero: Returns an infinite stream of null bytes, which can be used to initialize disks or create placeholder files.
  • /dev/full: Always returns a “No space left on device” error; it is primarily used for testing how software handles disk-full errors.
  • /dev/random: Provides an infinite stream of random data.

Versions of /dev/null exist on non-Unix systems too, like the NUL device on Windows.

So cheers to /dev/null. Always there for us and always ready to listen.

Filed under Culture◉ Join the discussion

Discussion

Loading comments…