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.

  • How are you specifying where the file goes ? Without writing a custom kernel module which creates a pseudo block device and then having you mount that, i don't really see how this could be done. My understanding in reading your question is you don't want the writes to take, and the program will not be reading back this information ? Is this for logs ? Are you sure there is no way of disabling this behavior ? Go with the accepted answer and see how that works out, it essentially is the same as what I just said so someone else already did it if it works. Jun 10 at 17:29
  • You could install tmpreaper, which is useful for cleaning up /tmp on systems that reboot seldom. Jun 12 at 3:03
  • What if the program write to the same file again and again? It could wear the storage device on the long term if it's an SSD but it should not fill the storage space.
    – A.L
    Jun 12 at 9:04
  • Can't you just use /dev/null directly, or a symlink to it?
    – Tanath
    Jun 12 at 22:37
  • @Tanath no, i need it for saving a file in a graphical program. i do not need the file itself
    – jp_
    Jun 13 at 10:41

1 Answer 1


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.

  • Bang, nice find and reference there. Also how many bounty points you'd guess you've lost in just deleted accounts that have awarded you bounty? 100, 1000, 200 million. Jun 11 at 17:01
  • 1
    Note that /tmp and /run are typically mounted as tmpfs, which exists as a ramdisk. They can and will run out of space if you write large files into them, so they're not necessarily suitable as a throwaway directory for arbitrary programs (imagine if the program in question wanted to write images or videos?)
    – Bob
    Jun 12 at 8:14
  • yes. true. i wanted to write big files(gcode). still text but i dont want my ram draining 5gb.
    – jp_
    Jun 17 at 8:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .