0

Is there any way to mount a folder content inside to another one?

Let's say I have 2 folders with following content;

Folder1       Folder2
  file1       file2

I basically want to make visible all of the content of Folder2 in Folder1. So the new content should be like this;

Folder1       Folder2
  file1       file2
  file2

And I also want Folder1 content to be updated when I do any change in Folder2. Let's say I've created file3 in Folder2. I'm expecting to see the new file under both of them.

Folder1       Folder2
  file1       file2
  file2       file3
  file3

So the general rules should be;

  • If you create/delete/modify any file under Folder2, it will be also visible under Folder1.
  • If you create/delete/modify any file in Folder 1 (which belongs to Folder2, for example removing file2), those changes will be done in Folder2.
  • User should not see any content of Folder1 under Folder2.

Any solution for that kind of requirement?

Thanks.

  • Why would one want to do this? It looks messy. – dr01 May 3 '18 at 13:42
  • For upstart conf files. I want to keep /etc/init tidy, so if I can do it, Folder1 will be /etc/init, and Folder2 will be my own service file folder which can reside anywhere in the system. – benjamin button May 3 '18 at 14:01
0

I'm not aware of anyway to directly do what you're asking, and you would of course encounter issues if file1 existed in both folder1 and folder2.

You could create links from each file/directory under folder2 to folder1, this would require a link per file/directory under folder2. You could create a script to keep the links updated and remove dead links.

If you used hard links then this would all be seamless when doing a directory listing etc.

You could then use inotify to watch folder1 and folder2 to trigger the creation/deletion of the hard links.

  • Creating another controller service is what I'm trying to escape, such as writing script. If I can mount the content of the folder2 into the folder1, and make it permanent, then there won't be any necessity to create a control mechanism. – benjamin button May 4 '18 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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