Linux file Basic Properties: Chown Modify the owning group and chmod modify file Properties command

Source: Internet
Author: User
Tags chmod readable file permissions

[[Email protected]/]#Ls-ltotal 64dr-xr-xr-x 24096 dec 14< Span class= "PLN" > 2012 Bin-rwxrwxr-x 44096 apr 19< Span class= "PLN" > 2012 main.c 

    • When [ D ] is the directory
    • When [ - ] is the document;
    • If [ l ] is indicated as a linked document (link file);
    • If [ b ] is indicated as the device file inside the storage interface device (can be random access device);
    • If [ C ] is indicated as a serial port device inside the appliance file, such as a keyboard, mouse (one-time reading device).

The No. 0 bit determines the file type,

第1-3位 determines that the owner of the file owns the file's permissions.

第4-6位 determines that the owning group (the same group of users of the owner) has permission to the file,

第7-9位 determines the permissions that other users have on the file.

1th, 4, 7-bit indicates Read permission

2nd, 5, 8 bits indicate write permission

3rd, 6, 9 bits indicate executable permissions

In a Linux system, users are categorized by group, and one user belongs to one or more groups.

[[Email protected]/]#Ls-Ltotal64Drwx R-x R-x 2Root root4096 feb 15 14 :46 Crond  rwx  r  - x  r  - x  34096 apr 21< Span class= "PLN" > 2014 MySQL        

This means that the root user group is not modifiable for other user groups

In the above example, the MySQL file is a directory file, both the owner and the group are MySQL,

The owner has a readable, writable, executable permission;

Other users in the same group as the owner have readable and executable permissions, and other users have readable and executable permissions.

For root users, the file's permissions generally do not work on it.

Change file properties 1, chgrp: Change file group

Grammar:

[-R] belongs to group name file   name

Parameter options

    • -R: Recursively change the group of files, that is, when you change the genus of a directory file, if you add the-r parameter, the group of all files under that directory will change.

Such as:

Chgrp-r DAOKR Test Change the directory of test to belong to the group DAOKR but DAOKR user cannot modify the catalog file

2, Chown: Change the owner of the file, you can also change the file group

Grammar:

chown [–R ]  main name   file name chown [-r]  file name                 


[Email protected]:/home$ chown-R daokr:daokr testchown: changing 'test/tt/m.c'  Owner: Disallowed action chown: changing the owner of 'test/tt'  : Action not allowed Chown: changing '  Test' owner: not allowed to

The permission group and the property master must be modified with the root user action

 [email protected]:/home# ls-l total usage  12  drwxr -xr-x 20  daokr daokr 4096  March 27  14 : 41   Daokr -rw-r--r--1  root root 19  March 27  Span style= "COLOR: #800080" >14 : 23   MAINTEST.CDRWXR -xr-x 3    DAOKR Daokr   4096  March 27  14 : 35  test 

3. chmod: Change file 9 Properties Change file read Only write-only executable properties

There are two ways to set up Linux file attributes, one is a number and one is a symbol.

Linux files have the basic permissions of nine, respectively, owner/group/others three identities each have their own Read/write/execute permissions. Read and Write execution permissions

First review the data just mentioned above: The file's permission character is: "-rwxrwxrwx", these nine permissions are three three a group ! Where we can use numbers to represent individual permissions, the scores for each permission are as follows:


First case: Number change

Numbers to represent individual permissions, the scores of each permission are as follows:

    • R:4
    • W:2
    • X:1

Each identity (Owner/group/others) 's respective three permission (R/W/X) scores are cumulative, such as when the permission is: [-rwxrwx---] score:

    • Owner = rwx = 4+2+1 = 7
    • Group = RWX = 4+2+1 = 7
    • others=---= 0+0+0 = 0

So wait a minute. When we set the permission change, the permission number of the file is 770! The syntax for the Change permission directive chmod is this:

[-R] file or directory  

Options and Parameters:

    • XYZ: is the permission attribute of the number type just mentioned, which is the sum of the numeric values of the Rwx property.
    • -R: Continuous change of recursion (recursive), i.e. all files in the secondary directory will be changed

For example, if you want to set all permissions for the. bashrc file to Enabled, the command is as follows:

Change the properties of the M.c file to rwx rwx---means that the  primary user permission is rwx=7 root user is rwx=7 other users have no permissions

 [email protected]:/home/test/tt$ ls-l total usage  4 -rw-r--r--1  daokr daokr 26  March 27  14 : 45   m.c[email protected] -sys:/home/test/tt $ chmod 770   M.C [email protected] -sys :/home/test/tt$ ls-l total usage  4 -rwxrwx---1  daokr daokr 26  March   14 : 45  m.c 
[Email protected]:/home/test/tt$ sudo chown daokr:root m.c[sudo] daokr password: [email protected]-sys:/home/test/ tt$ ls-41 March  :  m.c[email protected] -sys:/home/test/tt$ vim m.c [email protected] m.c

The above M.C modified the permission group root and the file attribute 440, indicating that both the Daokr user and the root user cannot modify the file, because it is a read-only file

Second case: Change by character

Basically nine permissions are (1) User (2) group (3) others three identities!
Then we can represent three kinds of identities by u, G, O!



In addition, a represents all and all identity! Then the permission to read and write can be written as R, W, x! That is, you can see it in the following way:

chmod U
G
O
A
+ (Join)
-(remove)
= (set)
R
W
X
File or directory

If we need to set the file permissions to -rwxr-xr-- , you can use the chmod u=rwx,g=rx,o=r file name to set:

[Email protected]:/home/test/tt$ chmod u=rwx,g=rwx,o=-M.c[email protected]-sys:/home/test/tt$ LS-L Total Dosage4-RWXRWX---1DAOKR Root -March -  -: $M.c[email protected]-sys:/home/test/tt$ chmod u=r-x,g=-wx,o=-M.c[email protected]-sys:/home/test/tt$ LS-L Total Dosage4-R--------1DAOKR Root +March -  the: *M.c[email protected]-sys:/home/test/tt$ chmod u=r-x,g=r,o=-M.c[email protected]-sys:/home/test/tt$ LS-L Total Dosage4-r--r-----1DAOKR Root +March -  the: *M.c[email protected]-sys:/home/test/tt$ chmod u=r-x,g=rw,o=-M.c[email protected]-sys:/home/test/tt$ LS-L Total Dosage4-R--RW----1DAOKR Root +March -  the: *M.c

And if you want to remove permissions without changing other existing permissions? For example, to take out the executable permissions of all people:

# chmod a-x test1# ls -al test1-rw-r--r-- 10 nov 15 10:32 test1          

Then

[Email protected]:/home/test/tt$ chmod a-x M.C
[Email protected]:/home/test/tt$ ls-l
Total Dosage 4
-R--RW----1 Daokr root 32 March 15:35 M.C
[Email protected]:/home/test/tt$ chmod u=rwx,g=rwx,o=r M.C
[Email protected]:/home/test/tt$ ls-l
Total Dosage 4
-rwxrwxr--1 daokr Root 32 March 15:35 M.C




Linux file Basic Properties: Chown Modify the owning group and chmod modify file Properties command

Related Article

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.