linux 目录 rwx(读写执行) 知多少?
2009-07-01 13:56
246 查看
linux/unix 下的文件 rwx 想必大家很熟悉了!但对目录的rwx是怎么理解的呢?
今天碰到了这个问题,一时还真回答不上来,例如:
目录执行权限能干吗?
目录只有写权限就可以写入文件到该目录了吗?
于是查看了一下资料,《Advanced Programming in the UNIX》中解释如下:
Note that read permission for a directory and execute permission for a directory
mean different things. Read permission lets us read the directory, obtaining a
list of all the filenames in the directory. Execute permission lets us pass
through the directory when it is a component of a pathname that we are trying to
access. (We need to search the directory to look for a specific filename.)
原来读权限仅仅是读取目录下的list(文件列表), 执行权限是access(访问)目录下的文件。
这下明白了,见用大学宿舍一哥们唱的一首《18摸》来解释:
读权限:“只能让你看,不能让你摸”
执行权限:“只能让你摸,不能让你看”
写权限:“先让摸,后让写” 换句话 “ 摸都不让,写也就没门了” (歌词没这句,呵呵!)
做实验证明:
root$ mkdir test/d1 -p
root$ touch test/f1
root$ echo "test" > test/f2
验证读权限:
root$ chmod 004 test (r读权限)
robin$ ls test (可以看到d1, f1, f2)
robin$ cat test/f2 (Permission denied)
root$ chmod 005 test (rx读执行权限)
robin$ cat test/f2 (看到“test”了)
验证执行权限:
root$ chmod 001 test (执行权限)
robin$ ls test (这边没有东西了哦!)
robin$ cat test/f2(可以看到“test”)
验证写权限:
root$ chmod 002 (w写权限)
robin$ echo "test2" > test/f3 (Permission denied)
root$ chmod 003 (wx写执行权限)
robin$ echo "test2" > test/f3 (成功)
这下清清楚楚! 不迷惑了!
由此可以看出:如果目录没有执行权限,搜索时也不会找到文件及其内容哦!
今天碰到了这个问题,一时还真回答不上来,例如:
目录执行权限能干吗?
目录只有写权限就可以写入文件到该目录了吗?
于是查看了一下资料,《Advanced Programming in the UNIX》中解释如下:
Note that read permission for a directory and execute permission for a directory
mean different things. Read permission lets us read the directory, obtaining a
list of all the filenames in the directory. Execute permission lets us pass
through the directory when it is a component of a pathname that we are trying to
access. (We need to search the directory to look for a specific filename.)
原来读权限仅仅是读取目录下的list(文件列表), 执行权限是access(访问)目录下的文件。
这下明白了,见用大学宿舍一哥们唱的一首《18摸》来解释:
读权限:“只能让你看,不能让你摸”
执行权限:“只能让你摸,不能让你看”
写权限:“先让摸,后让写” 换句话 “ 摸都不让,写也就没门了” (歌词没这句,呵呵!)
做实验证明:
root$ mkdir test/d1 -p
root$ touch test/f1
root$ echo "test" > test/f2
验证读权限:
root$ chmod 004 test (r读权限)
robin$ ls test (可以看到d1, f1, f2)
robin$ cat test/f2 (Permission denied)
root$ chmod 005 test (rx读执行权限)
robin$ cat test/f2 (看到“test”了)
验证执行权限:
root$ chmod 001 test (执行权限)
robin$ ls test (这边没有东西了哦!)
robin$ cat test/f2(可以看到“test”)
验证写权限:
root$ chmod 002 (w写权限)
robin$ echo "test2" > test/f3 (Permission denied)
root$ chmod 003 (wx写执行权限)
robin$ echo "test2" > test/f3 (成功)
这下清清楚楚! 不迷惑了!
由此可以看出:如果目录没有执行权限,搜索时也不会找到文件及其内容哦!
相关文章推荐
- linux 创建用户和 用户组,使其有某个目录的执行读写权限
- Linux目录读写和可执行权限
- Linux 文件和目录的读写执行权限详解
- linux网站目录最小权限分配-linux读写执行权限区别
- linux 系统,查看某目录下有多少个文件
- linux在目录中执行增删查(cd, touch, ls, rm, mv等)改文件动作需要的权限
- Linux 目录的读权限和执行权限的区别
- Linux设置任何目录下可以执行命令设置开机启动某个程序
- Linux下用bash命令执行名称中带有“(”符号的目录注意事项
- Linux中实现redis-cli命令在任意目录执行
- linux下目录读权限与执行权限区别
- 安装交叉编译工具,执行arm-linux-gcc –v命令出现提示找不到该文件或目录?解决方法
- Linux系统文件目录权限详解 - rwx
- linux 获取当前进程的可执行文件所在的目录
- LInux目录的写和执行权限
- 在 Linux 上给用户赋予指定目录的读写权限
- linux目录读和执行权限的区别
- 对linux的根目录执行强制递归移除
- linux怎么用一个命令行统计出给定目录中有多少个子目录
- linux下的文件权限(1)---普通的读写执行权限和ls命令详解