Linux Second week study notes (9)
2.15 change owner and owning group Chown
Chown (change owner) command: change the owner, or change the owning group
Chown-r command: the chown command only takes effect on the file or directory, only the user and the owning group of the specified directory itself, if you want to change the subdirectories and sub-files under the directory to the owner or the user group, It is necessary to use the-R parameter
--------------------------------------------------------------------------------
Chown command to change the owner of the file:
[Email protected] tmp]# ls-l
Total Dosage 8
-rw-r--r--1 root root 2564 1 moonrise 23:22 anaconda-ks.cfg.1
drwxr-xr-x 2 root root 1 moonrise 13:36 Daizhihong
d-wx--x---3 root root 1 Moon 21:58 daizhihong3
drwxr-xr-x 5 root root 1 moonrise 11:43 Daizhong
-RW-------. 1 root root 0 1 month 08:14 Yum.log
[email protected] tmp]# chown yngndzh1/tmp/yum.log (change yum.log owner ROOT to Yngndzh1)
[Email protected] tmp]# ls-l
Total Dosage 8
-rw-r--r--1 root root 2564 1 moonrise 23:22 anaconda-ks.cfg.1
drwxr-xr-x 2 root root 1 moonrise 13:36 Daizhihong
d-wx--x---3 root root 1 Moon 21:58 daizhihong3
drwxr-xr-x 5 root root 1 moonrise 11:43 Daizhong
-rw-------. 1 yngndzh1 root 0 1 month 08:14 Yum.log(owner change becomes yngndzh1)
--------------------------------------------------------------------------------------------
chgrp command to change the owning group of the file:
[Email protected] tmp]# ls-l/tmp/yum.log
-rw-------. 1 yngndzh1 root 0 1 month 08:14/tmp/yum.log
[Email protected] tmp]# Groupadd user
[email protected] tmp]# chgrp user/tmp/yum.log (change yum.log all group root to user group)
[Email protected] tmp]# ls-l/tmp/yum.log
-rw-------. 1 yngndzh1 user 0 1 month 08:14/tmp/yum.log (owning group changed to user)
----------------------------------------------------------------------------------------------
Chown command to change both the owner and the owning group of the file:
[Email protected] tmp]# ls-l/tmp/yum.log
-rw-------. 1 yngndzh1 user 0 1 month 08:14/tmp/yum.log
[email protected] tmp]# chown yngndzh2:root/tmp/yum.log (Use this method to change the owner and group of the file at the same time, instead of the CHGRP command)
[Email protected] tmp]# ls-l/tmp/yum.log
-rw-------. 1 yngndzh2 root 0 1 month 08:14/tmp/yum.log
------------------------------------------------------------------------------------------------
Chown The command changes the owning group:
[Email protected] tmp]# ls-l/tmp/yum.log
-rw-------. 1 yngndzh2 root 0 1 month 08:14/tmp/yum.log
[Email protected] tmp]# Chown:user/tmp/yum.log
[Email protected] tmp]# ls-l/tmp/yum.log
-rw-------. 1 yngndzh2 user 0 1 month 08:14/tmp/yum.log
[Email protected] tmp]#
--------------------------------------------------------------------------------------------
Chown-r command: Chown The command only takes effect on the file or directory, only the permissions specified by the directory itself, if you want to put the directory under the subdirectory and sub-files all the time to bulk change the owner or group of users, you need to use the-R parameter
[Email protected] tmp]# ls-l
Total Dosage 8
-rw-r--r--1 root root 2564 1 moonrise 23:22 anaconda-ks.cfg.1
drwxr-xr-x 2 root root 1 moonrise 13:36 Daizhihong
d-wx--x---3 root root 1 Moon 21:58 daizhihong3
drwxr-xr-x 5 root root 1 moonrise 11:43 Daizhong
[Email protected] tmp]# ls-l/tmp/daizhong/
Total dosage 0
drwxr-xr-x 2 root root 6 1 month 11:04(/daizhong/subdirectories)
drwxr-xr-x 2 root root 1 moonrise 23:09 daizhihong(/daizhong/subdirectories)
Drwxr-xr-x 2 root root 1 months 11:18 daizhihong2(/daizhong/subdirectories )
[Email protected] tmp]# chown- R Yngndzh1:user/tmp/daizhong
[Email protected] tmp]# ls-l
Total Dosage 8
-rw-r--r--1 root root 2564 1 moonrise 23:22 anaconda-ks.cfg.1
drwxr-xr-x 2 root root 1 moonrise 13:36 Daizhihong
d-wx--x---3 root root 1 Moon 21:58 daizhihong3
drwxr-xr-x 5 yngndzh1 user 1 moonrise 11:43 Daizhong
[Email protected] tmp]# ls-l/tmp/daizhong/
Total dosage 0
drwxr-xr-x 2 yngndzh1 user 6 1 month 11:04
drwxr-xr-x 2 yngndzh1 user 1 Moon 23:09 Daizhihong
drwxr-xr-x 2 yngndzh1 user 1 moonrise 11:18 daizhihong2
Join the-R parameter followed by a subdirectory or the child file belongs to the user and the owning group change together
Linux Second week study notes (9)