linuxfilesystemsvirtual-file

How to create a virtual command-backed file in Linux?


What is the most straightforward way to create a "virtual" file in Linux, that would allow the read operation on it, always returning the output of some particular command (run everytime the file is being read from)? So, every read operation would cause an execution of a command, catching its output and passing it as a "content" of the file.


Solution

  • There is no way to create such so called "virtual file". On the other hand, you would be able to achieve this behaviour by implementing simple synthetic filesystem in userspace via FUSE. Moreover you don't have to use c, there are bindings even for scripting languages such as python.

    Edit: And chances are that something like this already exists: see for example scriptfs.