5

If I already has a directory (A) with existing contents and another directory (B), how do I symbolic link such that the two directory's content merge.

   eg.   A 
           -> folderA1/
           -> a.bin
           -> b.bin (from B folder)
           -> c.bin (from B folder)
         B 
           -> b.bin
           -> c.bin
6

You could write a script that runs trough directory B that creates a link for every file in directory A. But, if you want to merge the two folders, I recommend using an overlay filesystem such as aufs. I use it myself for such a task.

Use the following mount command (You may have to install the tools to manage aufs):

mount -t aufs -o dirs=/path/to/dirA/=rw:/path/to/dirB/=ro none /path/to/mountpoint

Explanation of the mount command:

  • -t aufs: Sets the filesystem type to aufs
  • dirs=/path/to/dirA/=rw:/path/to/dirB/=ro: those are the directories you want to merge, sepatated by a :. It can also be a third directory if you want. Note that dirA is used as readwrite (rw) folder and dirB as readonly (ro). That means when you write into that mountpoint the filesystem writes into dirA, not dirB. There are lots of options, how the underlaying filesystem should behave in case of read or write. I recommend to see through the manual page.
  • none: this is the device. Because it's a pseudo filesystem, there is no device.
  • /path/to/mountpoint: the path where you want to mount the filesystem.
  • so its an filesystem on top of the unix default filesystem that perform the union. – Ethan Lim Sep 5 '14 at 7:23
  • Yes it's overlaid. The underlying filesystems could be everything. From a tmpfs over nfs to an usbfilesystem. – chaos Sep 5 '14 at 7:27

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.