0

I have two files: foo.txt and bar.txt. I want a file named foobar.txt that is the content of both foo.txt followed by bar.txt. And if I change either file, I want foobar.txt to still output whatever is currently in foo.txt followed by bar.txt.

Now to get foobar.txt, I could execute:

cat foo.txt bar.txt > foobar.txt

But I would have to do this every time I edit either source file.

Ideally I would like to do something like this:

ln -[some arg that uses a command rather than a real file] "cat foo.txt bar.txt" foobar.txt

Is this even possible?

Jason Thompson
  • 403
  • 2
  • 6
  • 15
  • A named pipe or such (`mkfifo(1)`) would be one option, or a `Makefile` that does the necessary `cat`, or perhaps inode change notification, depending on how complicated you want to make it. – thrig May 09 '16 at 15:59

2 Answers2

1

You can do this through inotifywait command, it is in inotify-tools package. This cannot be done through ln command as far as I can see.

Nasoo
  • 136
  • 7
0

You could write a FUSE (File System User spacE) to do it. This is basically write a user space program to act as a file system for the kernel. You could make it have whatever side effects you were willing to create, such as when your target file is opened, it caches the cat'ed foo.txt and bar.txt, and returns blocks from that cache.

Wikipedia has an article here: https://en.wikipedia.org/wiki/Filesystem_in_Userspace

It sounds like a lot of work for what you asking for.

infixed
  • 176
  • 4