Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 396
knaperek Avatar asked Aug 28 '14 21:08

knaperek


1 Answers

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.

like image 172
marbu Avatar answered Sep 27 '22 22:09

marbu