chgrp : 改变文件所属组
chown : 改变文件拥有者
chmod : 改变文件的权限
chgrp 这个命令就是 change group 的缩写,chgrp - R groupName FileName , 要改变的组名称必须要要在 /etc/group 内才行,否则报错:
[root@andy ~]# ll
total 64
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
[root@andy ~]# chgrp andy file
chgrp: invalid group `andy' //报错信息,找不到Andy组
[root@andy ~]#
total 64
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
[root@andy ~]# chgrp andy file
chgrp: invalid group `andy' //报错信息,找不到Andy组
[root@andy ~]#
[root@andy ~]# chgrp test file
[root@andy ~]# ll
total 64
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
[root@andy ~]#
[root@andy ~]# ll
total 64
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
[root@andy ~]#
chown , 就是 change owner 的缩写, UserName 必须在 /etc/passwd 中才行.
chown [ -R ] UserName FileName
chown [ -R ] UsetName:GroupName FileName
[root@andy ~]# ll
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 root test 4096 Oct 10 09:26 sj
[root@andy ~]# chown andy01 sj
[root@andy ~]# ll
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 andy01 test 4096 Oct 10 09:26 sj
[root@andy ~]#
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 root test 4096 Oct 10 09:26 sj
[root@andy ~]# chown andy01 sj
[root@andy ~]# ll
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 andy01 test 4096 Oct 10 09:26 sj
[root@andy ~]#
[root@andy ~]# ll
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 andy01 test 4096 Oct 10 09:26 sj
[root@andy ~]# chown -R root:root sj
[root@andy ~]# ll
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 root root 4096 Oct 10 09:26 sj
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 andy01 test 4096 Oct 10 09:26 sj
[root@andy ~]# chown -R root:root sj
[root@andy ~]# ll
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 root root 4096 Oct 10 09:26 sj
chmod : 数字类型改变文件权限
r : 4
w : 2
x : 1
owner = rwx = 4+2+1 = 7
group = rw- = 4+2 +0 = 6
others = r- - = 4+0+0 = 4
chmod [ -R ] 764 FileName
[root@andy ~]# ll
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 root root 4096 Oct 10 09:26 sj
[root@andy ~]# chmod 764 file
[root@andy ~]# ll
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rwxrw-r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 root root 4096 Oct 10 09:26 sj
[root@andy ~]#
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rw-r--r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 root root 4096 Oct 10 09:26 sj
[root@andy ~]# chmod 764 file
[root@andy ~]# ll
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rwxrw-r-- 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 root root 4096 Oct 10 09:26 sj
[root@andy ~]#
符号类型改变文件权限
chmod [ u , g , o , a ] [ + , - , = ] FileName
[root@andy ~]# chmod u=rwx,go=rx file
[root@andy ~]# ll
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rwxr-xr-x 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 root root 4096 Oct 10 09:26 sj
[root@andy ~]#
[root@andy ~]# ll
total 68
-rw------- 1 root root 2451 Oct 10 00:50 anaconda-ks.cfg
-rwxr-xr-x 1 root test 0 Oct 10 01:18 file
-rw-r--r-- 1 root root 34539 Oct 10 00:50 install.log
-rw-r--r-- 1 root root 8002 Oct 10 00:50 install.log.syslog
drwxr-xr-x 3 root root 4096 Oct 10 09:26 sj
[root@andy ~]#
转载于:https://blog.51cto.com/jialzt/210720