chmod修改文件权限:
1、字母法:chmod u/g/o/a +/-/= rwx 文件
[ u/g/o/a ] 含义
u: user 表示该文件的所有者
g: group 表示与该文件的所有者属于同一组( group )者,即用户组
o: other 表示其他以外的人
a: all 表示这三者皆是
[ +-= ] 含义
+: 增加权限
-: 撤销权限
=: 设定权限
rwx 含义
r: read 表示可读取,对于一个目录,如果没有r权限,那么就意味着不能通过ls查看这个目录的内容。
w: write 表示可写入,对于一个目录,如果没有w权限,那么就意味着不能在目录下创建新的文件。
x: excute 表示可执行,对于一个目录,如果没有x权限,那么就意味着不能通过cd进入这个目录。
han@glory:~/bioinformatics/test$ touch text.txt
han@glory:~/bioinformatics/test$ ls -lh
total 0
#-rw-rw-r--分别表示:第一个rw-, u; 第二个rw-,g;r--, o。
-rw-rw-r-- 1 han han 0 5月 24 10:44 text.txt
#添加rw-(即文件所有者)的可执行权限
han@glory:~/bioinformatics/test$ chmod u+x text.txt
han@glory:~/bioinformatics/test$ ls -lh
total 0
-rwxrw-r-- 1 han han 0 5月 24 10:44 text.txt
#同组中减去写的权限
han@glory:~/bioinformatics/test$ chmod g-w text.txt
han@glory:~/bioinformatics/test$ ll
total 8
drwxrwxr-x 2 han han 4096 5月 24 10:44 ./
drwxrwxr-x 13 han han 4096 5月 24 10:44 ../
-rwxr--r-- 1 han han 0 5月 24 10:44 text.txt*
han@glory:~/bioinformatics/test$ ls -lh
total 0
-rwxr--r-- 1 han han 0 5月 24 10:44 text.txt
#其他人添加写的权限
han@glory:~/bioinformatics/test$ chmod o+w text.txt
han@glory:~/bioinformatics/test$ ls -lh
total 0
-rwxr--rw- 1 han han 0 5月 24 10:44 text.txt
#如果需要同时进行设定拥有者、同组者以及其他人权限,参考如下:
han@glory:~/bioinformatics/test$ ls -lh
total 0
-rwxr--rw- 1 han han 0 5月 24 10:44 text.txt
han@glory:~/bioinformatics/test$ chmod u=rw,g=x,o=r text.txt
han@glory:~/bioinformatics/test$ ls -lh
total 0
-rw---xr-- 1 han han 0 5月 24 10:44 text.txt
注意:如果想递归所有目录加上相同权限,需要加上参数“ -R ”。 如:chmod 777 test/ -R 递归 test 目录下所有文件加相应权限
2、修改文件所有者:chown
#修改文件所有者,目前文件所有者为第一个han,修改为所有者为 yang
han@glory:~/bioinformatics/test$ ls -lh
total 0
-rwxr--rw- 1 han han 0 5月 24 10:44 text.txt
han@glory:~/bioinformatics/test$ chmod u=rw,g=x,o=r text.txt
han@glory:~/bioinformatics/test$ ls -lh
total 0
-rw---xr-- 1 han han 0 5月 24 10:44 text.txt
han@glory:~/bioinformatics/test$ sudo chown yang text.txt
[sudo] password for han:
han@glory:~/bioinformatics/test$ ls -lh
total 0
-rw---xr-- 1 yang han 0 5月 24 10:44 text.txt
3、修改文件所属组:chgrp
#目前文件所属组为han, 修改为XXX
han@glory:~/bioinformatics/test$ ls -lh
total 0
-rw---xr-- 1 yang han 0 5月 24 10:44 text.txt
han@glory:~/bioinformatics/test$ sudo chgrp XXX text.txt
han@glory:~/bioinformatics/test$ ls -lh
total 0
-rw---xr-- 1 yang XXX 0 5月 24 10:44 text.txt