What is /dev/null and why can't I use hx on it?

Several objects in /dev are pseudo-devices and are handled directly by kernel functions. The more frequently used ones are:

  • /dev/null: the universal sink of infinite capacity. Used to discard output: try echo foo >/dev/null. Reading from it returns an empty stream of bytes (immediate EOF).
  • /dev/zero: an infinite source of 0x00 bytes. Often used as input to overwrite things with 0s.
  • /dev/random, /dev/urandom: infinite sources of random bytes.

Indeed none of the other answers seem to actually answer the question of why hx refuses to work with /dev/null. The reason why hx reacts this way is simply that it was programmed to output this error message for device files.

From https://github.com/krpors/hx/blob/develop/editor.c#L125:

if (!S_ISREG(statbuf.st_mode)) {
        fprintf(stderr, "File '%s' is not a regular file\n", filename);
        exit(1);

That means that hx specifically refuses to work on anything that isn't a regular file. I don't think there is a very good reason for this check - without it, I would expect that /dev/null would work with hx, in the sense that hx would read an empty file, and any updates to it would be lost when saving them.

(This assumes that https://github.com/krpors/hx/ is really the hx programm the poster talks about)


/dev/null is basically a way to discard information.

The main purpose is simply to be able to redirect things into oblivion.

echo 'duck' > /dev/null

will suppress the message given by echo 'duck' as it's sent to /dev/null and therefore discarded.

This is mainly used when using commands that give you output that you don't want to see.

Reading from /dev/null immediately returns end of file — i.e., it acts like an empty file.

There is other fun things in /dev like random that will give you random data; not really what you expect from a "file" :) Worth noting is that /dev/random is true random data collected from usage in the system (time between keystrokes and things like that), and that pool can be exhausted rather fast. /dev/urandom give you what seem to be random number but is calculated by a math formula. Usually /dev/urandom is fine for your need, but for for instance very strong crypto keys it's not good enough.

You can also read from /dev/zero to get an endless stream of zero (null) bytes.