linux 挂载一个文件夹到另一个文件夹
2016-09-30 10:42
232 查看
挂载使用 mount --bind olddir newdir
卸载使用 umount newdir
-------------------------------------------------------------------------
转自: http://www.cnblogs.com/dabaopku/archive/2010/12/18/1909965.html
April 2006
Most Linux and Unix file systems don't allow hard links to directories (except for the . and .. entries that mkdir creates itself). The reasons are are pretty obvious: you could really confuse programs like ls (ls -R), find and of course fsck if you created
links that recursed back to themselves. If there was a compelling reason to allow directory hard links, you'd need to rewrite any program that wants to walk a file system tree to be aware of the possible problems..
So instead we have symlinks. You've probably used them for things like shifting around disk space or to give more convenient
access to a directory. For example, Mac OS X creates /tmp as a symbolic link to "private/tmp". We use symlinks to make other directories visible under Apache's htdocs directory (though the same thing can be accomplished with Apache's configuration files).
One problem with symbolic links is that really they are just files. A special kind of file, yes, but a symlink only points at a directory - it doesn't act like one. So, for example, if you put a symlink to /xyz in a users home directory, and the user has write
permission to his home (as he ordinarily would), he can remove your symlink. Nothing you can do with ordinary permissions can prevent that. You can do a "chattr +i" on your symlink, but because it is a symlink, that passes through to the actual directory,
making it unusable. If you use "+u" (undeletable), that again passes through, and the user still can delete your symlink.
This can be extremely annoying, especially when users accidentally delete a symlink they need to have. Of course your real directory is still safe, but you need to recreate the symlink. In the mean time, your user is confused or maybe even broken.
There is at least one way around this. If the thing you want to link to is a mounted file system, you can use the "--bind" option of mount to create an unbreakable link.
If the thing to link to it isn't a separate fs, you can almost always make it be one.
Here's how it works. Let's say we have /dev/foo mounted at /foo and I want a "link" to that under /home/fred. All I have to do is:
Fred can have full write permissions on /foo if he needs it, but he will not be able to remove /home/fred/foo. Not even root can:
Some related links you might find interesting:
http://lwn.net/Articles/159077/
http://linuxgazette.net/issue93/tag/2.html
卸载使用 umount newdir
-------------------------------------------------------------------------
转自: http://www.cnblogs.com/dabaopku/archive/2010/12/18/1909965.html
April 2006
Most Linux and Unix file systems don't allow hard links to directories (except for the . and .. entries that mkdir creates itself). The reasons are are pretty obvious: you could really confuse programs like ls (ls -R), find and of course fsck if you created
links that recursed back to themselves. If there was a compelling reason to allow directory hard links, you'd need to rewrite any program that wants to walk a file system tree to be aware of the possible problems..
So instead we have symlinks. You've probably used them for things like shifting around disk space or to give more convenient
access to a directory. For example, Mac OS X creates /tmp as a symbolic link to "private/tmp". We use symlinks to make other directories visible under Apache's htdocs directory (though the same thing can be accomplished with Apache's configuration files).
One problem with symbolic links is that really they are just files. A special kind of file, yes, but a symlink only points at a directory - it doesn't act like one. So, for example, if you put a symlink to /xyz in a users home directory, and the user has write
permission to his home (as he ordinarily would), he can remove your symlink. Nothing you can do with ordinary permissions can prevent that. You can do a "chattr +i" on your symlink, but because it is a symlink, that passes through to the actual directory,
making it unusable. If you use "+u" (undeletable), that again passes through, and the user still can delete your symlink.
This can be extremely annoying, especially when users accidentally delete a symlink they need to have. Of course your real directory is still safe, but you need to recreate the symlink. In the mean time, your user is confused or maybe even broken.
There is at least one way around this. If the thing you want to link to is a mounted file system, you can use the "--bind" option of mount to create an unbreakable link.
If the thing to link to it isn't a separate fs, you can almost always make it be one.
Here's how it works. Let's say we have /dev/foo mounted at /foo and I want a "link" to that under /home/fred. All I have to do is:
mount --bind /foo /home/fred/foo
Fred can have full write permissions on /foo if he needs it, but he will not be able to remove /home/fred/foo. Not even root can:
# rm -rf /home/fred/foo rm: cannot remove directory '/home/fred/foo': Device or resource busy
Some related links you might find interesting:
http://lwn.net/Articles/159077/
http://linuxgazette.net/issue93/tag/2.html
相关文章推荐
- linux 挂载一个文件夹到另一个文件夹
- 在Linux/Ubuntu下将一个文件从一个文件夹移动到另一个文件夹中
- Linux两块磁盘挂载指向一个文件夹LVM磁盘管理(一)
- linux 将一个服务器上的文件或文件夹拷贝到另一个服务器上
- linux复制文件夹到另一个文件夹并排除一个文件夹
- Linux两块磁盘挂载指向一个文件夹LVM磁盘管理(三)
- linux怎么将一个文件下的部分文件,拷贝到另一个文件夹下
- Linux 把一个文件夹下的所有内容复制到另一个文件夹下面
- linux强制复制一个文件夹的所有内容到另一个文件夹,跳过确认
- Linux两块磁盘挂载指向一个文件夹LVM磁盘管理(二)
- 挂载本地一个文件夹到另一个文件夹
- 终端中以窗口形式打开一个文件夹and回收站and删除软件and挂载分区and软件源更新and安装JDKandMySQLand安装图解:Linux Mint 4.0
- linux怎么将一个文件夹链接到另一个文件夹上
- 每天学点linux--(用shell实现将一个文件夹下面的所有文件拷贝到另一个文件夹下/shell下如何重命名一个文件)
- linux挂载windows分区和linux下带空格文件夹名表示方法
- 在linux中怎样用命令完全拷贝一个目录下的所有文件(包括隐藏文件以及文件夹)到另外一个目录下
- 利用 linux 的 7za 备份文件,如何排除一个文件夹
- linux如何搜索一个文件夹下包含某个字段的文件
- [PHP][Function]实现将一个文件夹下的所有文件及文件夹复制到另一个文件夹里(保持原有结构)[已验证][原创]
- ubuntu下NFS安装与配置(实现两台linux之间的文件夹挂载与共享访问)