Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to maintain a set of plain text files saved in a directory which all have a section taken from another file. An example follows:


/directory/textfile1 (every other file in the directory needs to "include" the
                      full contents of this file, each file can do so at a
                      different starting position; this file changes often      )
/directory/textfile2 ("includes" textfile1 after a few lines from the top       )
/directory/textfile3 ("includes" textfile1 as a header                          )
/directory/textfile4 ("includes" textfile1 as a footer                          )

Upon changing textfile1, I would like filesystem reads hitting textfile{2..4} to return updated versions with the new content from textfile1.

On web servers, this would be solved with the traditional server side include directives. Now, how would I do that without running a front-end service?

Could I create a symlink that, rather than pointing to another inode, runs some custom code and presents stdout as the contents of the file, somehow like defining custom "reparse points"?

The hypotetical "symlink" would, for instance, run this for file textfile3:

cat /directory/textfile1 /directory/textfile3_static

and thus simulate the existence of a static file whose content depends on textfile1.

I am looking for a solution that uses the least amount of customisation, not writing a custom FUSE module for a special mount point or anything like that.

I may be thinking in the wrong direction here, perhaps it would be easier to trigger an update script replacing placeholders at every modification of textfile1? How could one trap that event without polling for it?

Here some sample text files:


Ferma non stai sei come un ciclone
e non dormi mai

Juny tu hai un cervellone
quasi tutto sai
Ma quando fai un'invenzione
sono sempre guai
Ferma non stai sei come un ciclone
e non dormi mai
Il centauro Nico ami già
ma lui forse non lo sa

Ferma non stai sei come un ciclone
e non dormi mai
Il centauro Nico ami già
ma lui forse non lo sa

Come sempre insisterai
allora che pasticci tu di nuovo farai

... etcetera. :)

share|improve this question
Would it be acceptable for you to use read-wrapper-scripts? – rozcietrzewiacz Aug 28 '11 at 19:16
@rozcietrzewiacz: read-wrapper-scripts? As in? Could you provide an example or an elucidatory link, please? – Robottinosino Aug 28 '11 at 21:03
I meant scripts that you'd execute instead of reading each file. But I see the answers about named pipes achieve this in a better way. – rozcietrzewiacz Aug 28 '11 at 21:08
up vote 2 down vote accepted

Translating somehow the @polynomial answer to bash:


if [[ ! -e textfile2 ]]; then
  mkfifo textfile2

while true; do
    exec >textfile2
    cat textfile2-header
    cat textfile1
    cat textfile2-footer
share|improve this answer

You could do this with named pipes. Basically you would maintain your text files somewhere as 'templates' and a script like this perl example:


Would open 'textfile3' as a pipe and when it got a read request it would dump the contents that textfile3 should contain (perhaps by reading textfile3.template and replacing the contents as needed). This would allow you to dynamically change the contents without having to update multiple files and with minimal configuration.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.