15

I want a /dev/null directory, to which a graphical program can write a file, and think that it actually is writing it, like redirecting stdout to /dev/null. I can't write it to /tmp, as I nearly never reboot my system and that would make the hard disk full. I also don't want to delete the file afterwards.

chicks
  • 590
jp_
  • 290

1 Answers1

25

The post How can I create a /dev/null-like "blackhole" directory? suggests this :

This isn't supported out-of-the-box on any unix I know, but you can do pretty much anything with FUSE. There's at least one implementation of nullfs, a filesystem where every file exists and behaves like /dev/null (this isn't the only implementation I've ever seen).

The post Is there a directory equivalent of /dev/null in Linux? has this much-upvoted answer:

The FHS provides no "standard" empty directory.

It is common for Linux systems to provide a directory /var/empty, but this directory is not defined in FHS and may not actually be empty. Instead, certain daemons will create their own empty directories in here. For instance, openssh uses the empty directory /var/empty/sshd for privilege separation.

If your need for an empty directory is transient, you can create an empty directory yourself, as a subdirectory of /run or /tmp. If you're doing this outside the program, you can use mktemp -d for this, or use the mkdtemp(3) C function inside your program. Though if you always need the empty directory to be present, consider creating one under /var/empty as openssh does.

For this use case, creating a directory under /tmp is probably the best fit, though in practice it doesn't matter very much where you put it.

harrymc
  • 498,455