Linux权限对文件和目录的作用

一 权限对文件的作用
r:读取文件内容(cat more head tail)
w:编辑、新增、修改文件的内容(vi echo)
但不包含删除文件
x:可执行
 
二 权限性对目录的作用
r:可以查询目录下文件名(ls)
w:具有修改目录结构的权限。如新建文件和目录,删除此目录下文件和目录,重命令此目录下的文件和目录,剪切(touch rm mv cp)
x:可以进入目录(cd)
 
三 关于最高权限
对文件来讲,最高权限是x
对目录来讲:最高权限是w
对目录来讲,能赋的权限只有0.5.7
对目录光有只读权限是没有任何意义的
 
四 实战
1、不给user1用户赋予文件abc的任何权限,不对123目录任何权限。
root用户操作:
[root@localhost user1]# ll
total 0
drwxr-x---. 2 root root 16 Aug 5 09:19 123
[root@localhost user1]# ll 123/abc
-rw-r-----. 1 root root 0 Aug 5 09:19 123/abc
user1用户操作:
[user1@localhost ~]$ ll 123
ls: cannot access 123: No such file or directory
[user1@localhost ~]$ ls
123
[user1@localhost ~]$ ls 123
ls: cannot open directory 123: Permission denied
[user1@localhost ~]$ cd 123
-bash: cd: 123: Permission denied
2、给user1用户的123目录赋予只读权限
root用户操作
[root@localhost user1]# chmod 754 123
[root@localhost user1]# ll
total 0
drwxr-xr--. 2 root root 16 Aug 5 09:19 123
user1用户操作
[user1@localhost ~]$ ls 123
ls: cannot access 123/abc: Permission denied
abc
[user1@localhost ~]$ ll 123/
ls: cannot access 123/abc: Permission denied
total 0
?????????? ? ? ? ? ? abc
[user1@localhost ~]$ cd 123
-bash: cd: 123: Permission denied
3、对user1用户的123目录赋5权限
root用户操作
[root@localhost user1]# chmod 755 123
user1用户操作
[user1@localhost ~]$ ll 123/
total 0
-rw-r-----. 1 root root 0 Aug 5 09:19 abc
[user1@localhost ~]$ cd 123
[user1@localhost 123]$ ll
total 0
-rw-r-----. 1 root root 0 Aug 5 09:19 abc
[user1@localhost 123]$ cat abc
cat: abc: Permission denied
[user1@localhost 123]$
4、给文件abc赋644
root用户操作:
[root@localhost user1]# chmod 644 123/abc
[root@localhost user1]# ll 123/abc
-rw-r--r--. 1 root root 0 Aug 5 09:19 123/abc
user1用户操作:
[user1@localhost 123]$ cat abc
[user1@localhost 123]$ echo 111 >> abc
-bash: abc: Permission denied
5、对文件abc赋646
root用户操作:
[root@localhost user1]# chmod 646 123/abc
[root@localhost user1]# ll 123/abc
-rw-r--rw-. 1 root root 0 Aug 5 09:19 123/abc
user1用户操作
[user1@localhost 123]$ echo 111 >> abc
[user1@localhost 123]$ cat abc
111
[user1@localhost 123]$ rm -rf abc
rm: cannot remove ?.bc?. Permission denied
7、对目录123赋757权限
root用户操作
[root@localhost user1]# chmod 757 123
[root@localhost user1]# ll
total 0
drwxr-xrwx. 2 root root 16 Aug 5 09:19 123
user1用户操作
[user1@localhost 123]$ rm -rf abc
[user1@localhost 123]$ ls
[user1@localhost 123]$ touch bcd
[user1@localhost 123]$ mv bcd cde
 

猜你喜欢

转载自cakin24.iteye.com/blog/2393395
今日推荐