欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入
举例
[root@localhost ~]# ll baa
-rw-r–r– 1 root root 176 2007-01-06 baa
[root@localhost ~]# chmod 754 baa
[root@localhost ~]# ll baa
-rwxr-xr– 1 root root 176 2007-01-06 baa
[root@localhost ~]# chmod u=rw,g=x,o=x baa
[root@localhost ~]# ll baa
-rw—x–x 1 root root 176 2007-01-06 baa
[root@localhost ~]# chmod a+w baa
[root@localhost ~]# ll baa
-rw–wx-wx 1 root root 176 2007-01-06 baa
[root@localhost ~]#
目录与文件权限的意义
R(Read):可读取此文件的实际内容,如读取文本文件的文件内容
当你具一个目录读取r 权限。表示你可以查看该目录下的文件名结构。
W(write): 可以编辑,新增或者是修改该文件的内容(但不含删除该文件)
当你具一个目录写入w 权限。表示你可以更改该目录结构
1. 新建新的文件与目录
2. 删除已经存在的文件和目录(不论该文件的权限是什么)
3. 将以存在的文件或目录进行重命名
4. 转移该目录内的文件,目录位置
X(execute):该文件具有可以被系统执行的权限(对于目录来说X就是进入文件夹的权限)
举例
[root@localhost ~]# mkdir -m 000 /tmp/testdir //root 用户权限为000的 文件夹testdir
[root@localhost ~]# cd /tmp/testdir/ //超级用户无权限也可进入
[root@localhost testdir]# touch testfile //创建文件
[root@localhost testdir]# chown tkf . // 将文件夹testdir用户变更为tkf,以便一会切换用户操作
[root@localhost testdir]# ls -ald /tmp/testdir/ ./testfile
-rw-r–r– 1 root root 0 02-19 12:59 ./testfile
d——— 2 tkf root 4096 02-19 12:59 /tmp/testdir/
[root@localhost testdir]# su tkf //切换用户
[tkf@localhost testdir]$ cd ..
[tkf@localhost tmp]$ ll ./testdir/ //无r权限
ls: ./testdir/: 权限不够
[tkf@localhost tmp]$ chmod u+r ./testdir //分配r权限
[tkf@localhost tmp]$ ll ./testdir/
?——— ? ? ? ? ? testfile //可以看到目录结构 但是因为无X权限,目录下文件属性看不到
[tkf@localhost tmp]$ cd testdir/ //无x权限
bash: cd: testdir/: 权限不够
[tkf@localhost tmp]$ chmod u=rx ./testdir //分配rx权限
[tkf@localhost tmp]$ ll ./testdir/
-rw-r–r– 1 root root 0 02-19 12:59 testfile //可以看到目录结构和文件属性
[tkf@localhost tmp]$ cd testdir/
[tkf@localhost testdir]$ rm -f testfile //无W权限,不能删除目录下的文件
rm: 无法删除 “testfile”: 权限不够
[tkf@localhost tmp]$ chmod u=w ./testdir //仅分配W权限
[tkf@localhost tmp]$ ls -ald ./testdir/
d-w——- 2 tkf root 4096 02-19 12:59 ./testdir/
[tkf@localhost tmp]$ rm ./testdir/testfile //缺少X权限 因此删不了
rm: 无法删除 “./testdir/testfile”: 权限不够
[tkf@localhost tmp]$ chmod u=rw ./testdir //分配RW权限
[tkf@localhost tmp]$ rm ./testdir/testfile //缺少X权限 因此删不了
rm: 无法删除 “./testdir/testfile”: 权限不够
[tkf@localhost tmp]$ chmod u=wx ./testdir //分配XW权限
[tkf@localhost tmp]$ rm ./testdir/testfile //可以删除文件,同时文件的用户属于root ,在tkf用户仍可以删除
rm:是否删除有写保护的 一般空文件 “./testdir/testfile”? y
1.如果目录只有R权限。可以查看目录下文件结构,但是看不到文件属性,并且进入不了目录(cd)
2.如果目录有RX权限,可以查看目录下文件结构和属性,并且可以进入目录
3.要删除目录下的文件。目录至少需要WX权限
[1][2]
可就是这样,还是有人,期望过多的温暖。