Linux Learning Note 2 chgrp chmod chown

Source: Internet
Author: User
Tags readable


chgrp Change Group changes the user group that the file belongs to eg. Chgrp-r User 1.txt

[[email protected] test]# ll   Query the files and properties under the test directory total 0                   is now empty, no files [[email protected ] test]# touch 1.txt   established 1.txt[[email protected] test]# touch 2. txt[[email protected] test]# touch 3.txt[[email protected] test]#  ll query the files and properties under the test directory Total 0-rw-r--r--.  1 root root 0 Jan 25 11:44  1.txt   file Property-rw-r--r--.  1 root root 0 jan 25 11:44 2. Txt-rw-r--r--.  1 root root 0 jan 25 11:44 3.txt[[email protected]  test]# chgrp srd 1.txt   change 1.txt to SRD-owned group [[email protected] test]#  Ll   total 0-rw-r--r--.  1 root srd  0 jan 25 11:44 The  1.txt 1.txt file belongs to a group that has been converted to SRd The-rw-r--r--.  1 root root 0 jan 25 11:44 2.txt-rw-r--r--.  1  Root root 0 jan 25 11:44 3.txt


chmod Change Mode changes the file properties, and the file attributes are set in two ways: numbers and tags.

The pattern is as follows: [Ugoa ...] [[+-=][RWXX] ...] [,...], in which u represents the owner of the file, G represents the group to which the owner of the file belongs, and O represents the other person, and a means that all three are. + means add permission,-means dismiss permission, = indicates only set permission. R means readable, w means writable,x table implies executable

eg. Set file 1.txt to be readable by everyone: chmod ugo+r 1.txt or chmod a+r file1.txt

The files 1.txt and 2.txt are set to the owner of the file, and the person to whom it belongs can be written to, but not others: chmod ug+w,o-w 1.txt 2.txt

Set 3.txt to only the owner of the file can be implemented: chmod u+x 3.txt

Set all files in the current directory to be readable by anyone: chmod-r A+r *


[email protected] test]# LL

Total 0

-rw-r--r--. 1 root SRD 0 Jan 11:44 1.txt

-rw-r--r--. 1 root root 0 Jan 11:44 2.txt

-rw-r--r--. 1 root root 0 Jan 11:44 3.txt

[Email protected] test]# chmod a+w 1.txt

[email protected] test]# LL

Total 0

-rw-rw-rw-. 1 root SRD 0 Jan 11:44 1.txt

-rw-r--r--. 1 root root 0 Jan 11:44 2.txt

-rw-r--r--. 1 root root 0 Jan 11:44 3.txt



Chmod can also use numbers to represent permissions such as chmod 777 file

The syntax is: chmod ABC file

This a,b,c is a number that represents the permissions of the user, Group, and other respectively.

R=4,w=2,x=1

The Rwx property is 4+2+1=7, the Rw-property is 4+2=6, and the R-x property is 4+1=5.

eg. chmod a=rwx file and chmod 777 file result

chmod ug=rwx,o=x file and chmod 771 file result


[email protected] test]# LL

Total 0

-rw-rw-rw-. 1 root SRD 0 Jan 11:44 1.txt

-rw-r--r--. 1 root root 0 Jan 11:44 2.txt

-rw-r--r--. 1 root root 0 Jan 11:44 3.txt

[Email protected] test]# chmod 777 2.txt

[email protected] test]# LL

Total 0

-rw-rw-rw-. 1 root SRD 0 Jan 11:44 1.txt

-rwxrwxrwx. 1 root root 0 Jan 11:44 2.txt

-rw-r--r--. 1 root root 0 Jan 11:44 3.txt


chown Change owner changes file owner

Chown-r-H User name file/directory,-r option means that all subdirectories under the same operation,- The h option means that the target file that the link points to is not affected when the owner of the symbolic link file is changed. NOTE: Once ownership of the file is given to another user, it can no longer be re-owned and can only be resorted to by the system administrator.

Chown User name: User group: File/directory, if the entire directory is changed, then the plus-r parameter is used for recursion.

Chown-r root/etc/config.cfg

Chown-r Root:root/home

[[email protected] test]# ll change pre-query

Total 0

-rw-rw-rw-. 1 root SRD 0 Jan 11:44 1.txt

-rwxrwxrwx. 1 root root 0 Jan 11:44 2.txt

-rw-r--r--. 1 root root 0 Jan 11:44 3.txt

[[email protected] test]# chown SRD 1.txt Modified

[[email protected] test]# ll change pre-query

Total 0

-rw-rw-rw-. 1 SRD SRD 0 Jan 11:44 1.txt File The owner has changed

-rwxrwxrwx. 1 root root 0 Jan 11:44 2.txt

-rw-r--r--. 1 root root 0 Jan 11:44 3.txt


Linux Learning Note 2 chgrp chmod chown

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.