Link CentOS 7 中的目录

Link directories in CentOS 7

您好,我在 CentOS 服务器上,我有一个名为 'theowner' 的用户,所以他的文件夹在 /home/theowner

另一方面,我在 /home/myprojects/src 下有 2 个文件夹,f1 和 f2,我只想让这些文件夹出现在 /home/theowner 下,但我不想移动文件夹 我要的是link那2个文件夹到/home/theowner。它适用于 c9 工作区,我只想允许所有者在登录时直接访问该文件夹。谢谢!

尝试创建符号链接:

ln -s /home/myprojects/src/f1/ /home/theowner/

ln -s /home/myprojects/src/f2/ /home/theowner/

@Lubomir 已经给出了符号链接解决方案。

但是,他的解决方案将要求 theowner 至少对 /home/myprojects/src/f1/home/myprojects/src/f2 的所有父目录具有 read-execute 权限。

在大多数情况下,您不希望 theowner 看到 /home/myprojects/src/f1/home/myprojects/src/f2 之外的任何内容。

绑定坐骑来拯救。

作为theowner创建以下目录。

$ mkdir f1 f2

作为root,将源目录挂载到目标目录。

# mount -o bind /home/myprojects/src/f1 /home/theowner/f1
# mount -o bind /home/myprojects/src/f2 /home/theowner/f2

如果您希望它在重新启动后仍然存在,请在 /etc/fstab

中添加 2 个条目
/home/myprojects/src/f1  /home/theowner/f1  auto  auto,bind  0 0
/home/myprojects/src/f2  /home/theowner/f2  auto  auto,bind  0 0

使用此解决方案,theowner 不需要访问 /home/myprojects/src/f1/home/myprojects/src/f2.

的父目录