首页 > Linux 文件权限设置问题

Linux 文件权限设置问题

在Linux下如何设置一个目录可读、可写、不可删除,但是目录内的文件可以删除?


把它作为一个mount point。

例:

准备一个镜像(当然你也可以直接用一个分区)

felix021@ubserver:~/test$ dd if=/dev/zero of=disk bs=1M count=128
128+0 records in
128+0 records out
134217728 bytes (134 MB) copied, 0.779999 s, 172 MB/s
felix021@ubserver:~/test$ mke2fs disk
mke2fs 1.42 (29-Nov-2011)
disk is not a block special device.
Proceed anyway? (y,n) y
...
Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

挂载

felix021@ubserver:~/test$ sudo mount -oloop disk mnt

删除

felix021@ubserver:~/test$ sudo rm -rf mnt
rm: cannot remove `mnt': Device or resource busy


对于目录本身,将它的上级目录设置为不可写,那么该目录就不可删除了。
对于目录下的文件,直接把目录的权限设为RWX,用户就拥有对该目录下文件的删除、新建和访问权限。

【热门文章】
【热门文章】