文件权限的操作
1.查看文件的权限
可以通过cd xxx(路径)打开文件所在路径,
然后通过ll命令的前面的一段文字查看文件的权限
cd /home/yys/Desktop
yys@ubuntu:~/Desktop$ ll
total 32
d(d代表是文件夹)rwxr-xr-x 3 yys(用户名) yys(组名) 4096 May 2 19:23 ./
drwxr-xr-x 17 yys yys 4096 May 1 10:28 ../
-(-代表是二进制文件,文本文件也属于二进制文件)rw-rw-r-- 1 yys yys 34 May 2 18:41 122.txt
-rw-rw-r-- 1 yys yys 34 May 2 18:54 123.txt
-rw-rw-r-- 1 yys yys 362 May 2 18:59 124.txt
-rw-rw-r-- 1 yys yys 215 May 2 19:23 125.txt
-rw-rw-r-- 1 yys yys 10 May 2 18:27 12.odt
drwxrwxr-x 2 yys yys 4096 May 2 19:25 aa/
如代码段所示:
d rwx r-x r-x 3 yys yys 4096 May 2 19:23 ./
第一个字母d代表文件夹文件;-代表二进制文件(文本文件也属于二进制文件)
2、3、4为一组,代表用户的三种权限
5、6、7为一组,代表文件所属组的三种权限
8、9、10为一组,代表其他人的三种权限
假如一个用户没有文件A的权限,但是用户组拥有A的权限,那么该用户同样可以对文件A进行操作
r 列出文件列表(读)
w 查看修改该文件(写)
x 删除和创建文件(执行)
- 无该权限
2.操作
2.1.1chmod 命令-直接使用rwx(看操作怎么用)
chmod u+x 12.odt (给12.odt文件赋予可执行的权限)
yys@ubuntu:~/Desktop$ ll
total 32
drwxr-xr-x 3 yys yys 4096 May 2 19:23 ./
drwxr-xr-x 17 yys yys 4096 May 1 10:28 ../
-rw-rw-r-- 1 yys yys 34 May 2 18:41 122.txt
-rw-rw-r-- 1 yys yys 34 May 2 18:54 123.txt
-rw-rw-r-- 1 yys yys 362 May 2 18:59 124.txt
-rw-rw-r-- 1 yys yys 215 May 2 19:23 125.txt
-rwxrw-r-- 1 yys yys 10 May 2 18:27 12.odt*
drwxrwxr-x 2 yys yys 4096 May 2 19:25 aa/
chmod u-x 12.odt (去掉12.odt的可执行权限)
yys@ubuntu:~/Desktop$ ll
total 32
drwxr-xr-x 3 yys yys 4096 May 5 16:01 ./
drwxr-xr-x 17 yys yys 4096 May 1 10:28 ../
-rw-rw-r-- 1 yys yys 34 May 2 18:41 122.txt
-rw-rw-r-- 1 yys yys 34 May 2 18:54 123.txt
-rw-rw-r-- 1 yys yys 362 May 2 18:59 124.txt
-rw-rw-r-- 1 yys yys 215 May 2 19:23 125.txt
-rw-rw-r-- 1 yys yys 10 May 2 18:27 12.odt
drwxrwxr-x 2 yys yys 4096 May 2 19:25 aa/
chmod u-rw,o-rw 12.odt (同时修改用户和组权限)
yys@ubuntu:~/Desktop$ ll
total 32
drwxr-xr-x 3 yys yys 4096 May 5 16:01 ./
drwxr-xr-x 17 yys yys 4096 May 1 10:28 ../
-rw-rw-r-- 1 yys yys 34 May 2 18:41 122.txt
-rw-rw-r-- 1 yys yys 34 May 2 18:54 123.txt
-rw-rw-r-- 1 yys yys 362 May 2 18:59 124.txt
-rw-rw-r-- 1 yys yys 215 May 2 19:23 125.txt
----rw---- 1 yys yys 10 May 2 18:27 12.odt
drwxrwxr-x 2 yys yys 4096 May 2 19:25 aa/
chmod u=rw,o=r,g=rw 12.odt (使用=直接操作u/g/o的权限)
yys@ubuntu:~/Desktop$ ll
total 32
drwxr-xr-x 3 yys yys 4096 May 5 16:01 ./
drwxr-xr-x 17 yys yys 4096 May 1 10:28 ../
-rw-rw-r-- 1 yys yys 34 May 2 18:41 122.txt
-rw-rw-r-- 1 yys yys 34 May 2 18:54 123.txt
-rw-rw-r-- 1 yys yys 362 May 2 18:59 124.txt
-rw-rw-r-- 1 yys yys 215 May 2 19:23 125.txt
-rw-rw-r-- 1 yys yys 10 May 2 18:27 12.odt
drwxrwxr-x 2 yys yys 4096 May 2 19:25 aa/
2.1.2chmod 命令-用数字表示权限(看操作怎么用)
r 4
w 2
x 1
chmod 646 12.odt (同时对三个权限进行操作,简便但是需要计算容易出错)
yys@ubuntu:~/Desktop$ ll
total 32
drwxr-xr-x 3 yys yys 4096 May 5 16:01 ./
drwxr-xr-x 17 yys yys 4096 May 1 10:28 ../
-rw-rw-r-- 1 yys yys 34 May 2 18:41 122.txt
-rw-rw-r-- 1 yys yys 34 May 2 18:54 123.txt
-rw-rw-r-- 1 yys yys 362 May 2 18:59 124.txt
-rw-rw-r-- 1 yys yys 215 May 2 19:23 125.txt
-rw-r--rw- 1 yys yys 10 May 2 18:27 12.odt
drwxrwxr-x 2 yys yys 4096 May 2 19:25 aa/
2.2修改拥有者
chown xx(用户名) xx(文件(夹))
如果报错,就是权限不够,在开头加上sudo
2.3修改拥有组
chgrp xx(组名) xxx(文件(夹))
如果报错,就是权限不够,在开头加上sudo