Linux Second week study notes (9)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.