3

It's a known fact that you cannot create hard links for directories.

My question is whether can one use mount --bind dir1 dir2

instead of creating a hardlink of dir1 to dir2? which can't happen

1

Yes, with mount --bind you can make the same content (especially directories) appear in the file system twice.

For a very comprehensive article about this please see What is a bind mount? on unix.stackexchange.com

Most important points:

  1. Bind mounts are "just" an alternate way of viewing the contents of the file system.
  2. They may cross filesystem boundaries and span chroot jails.
  3. You can use them for directories (for instance to prepare a chroot by providing access to the /proc, /sys and /dev file systems (see mount dev, proc, sys in a chroot environment? on superuser.com)
  4. Quoted from Gilles' answer I mentioned above:

Unlike a hard link or symbolic link, a bind mount doesn't affect what is stored on the filesystem. It's a property of the live system.

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.