linux study (six) basic file attributes

Linux system is a typical multi-user systems, different users have different status, with different privileges. To protect the security of the system, Linux system access the same file (including directory files) for different users to do different provisions.

In Linux we can use ll or ls -l command to display user and group attributes of a file and the file belongs to, such as:

[root@www /]# ls -l
total 64
dr-xr-xr-x   2 root root 4096 Dec 14  2012 bin
dr-xr-xr-x   4 root root 4096 Apr 19  2012 boot
……

Example, a first bin file attribute is represented by "d". "D" represents the Linux in the file is a directory file.

In Linux the first character represents the file is a directory, the file or linked files, and so on.

  • As for the [  D] is a directory
  • As for the [  -] is a file;
  • If [  L] is represented as a linked document (link file);
  • If the [  B] indicates that the interface device is a device for storage of the files inside (random access device);
  • If the [  C] indicates the serial port device is a file inside the device, such as a keyboard, a mouse (one reading device).

    The next character to three as a group, and are a combination of three parameters of "rwx" of. Wherein, on behalf of [r] read (read), [w] Representative writable (write), [x] Representative executable (execute). It should be noted that the location of these three privileges do not change, if there is no authority, there will be a minus sign [-] only.

    Attribute of each file is determined by the character of the first portion 10 to the left (as shown below).

 

 

 

From left to right are represented by the numbers 0-9.

Bit 0 determine file types, positions 1-3 to determine the owner (owner of the file) have access to the file.

The first set 4-6 to determine the genus (group of users with the owners) have access to the file, 7-9 bits identify other users who have access to the file.

 

Among them, 1,4,7 indicates read permission, if the "r" character said it has read access, if the "-" character, there is no read permission;

5, 8 bits represent write permission, if the "w" character, said the written authority, if the "-" character does not have write permission; 3,6,9 indicates the first executable permissions, if " x "character says the Executive authority, if the" - "character is not authorized to perform.

Linux file the owner and group

[root@www /]# ls -l
total 64
drwxr-xr-x 2 root  root  4096 Feb 15 14:46 cron
drwxr-xr-x 3 mysql mysql 4096 Apr 21  2014 mysql
……

For files, it has a particular owner, that is, the user has the file ownership.

Meanwhile, in the Linux system, users are classified into groups of one or more users belonging to one group.

Users outside of the owner of the file can be divided into the same group of users of the file owner and other users.

Therefore, Linux system by file owner, file owner with the group and other users to specify a different file access rights.

In the above example, mysql file is a directory file, the owner and group are mysql, owner have read, write, execute permissions; other users of the same group owner has readable and executable by permissions; other users have permission readable and executable.

For root users, under normal circumstances, it does not work the file permissions.

Change the file attributes

1, chgrp: Change the file owner group

grammar:

chgrp [-R] filename is a group

Parameter options

  • -R: recursively change the file belongs to the group, that is, when you change a file's directory belong to the group, if coupled with -R parameter, then the group will change belongs to all the files in that directory.

2, chown: Change file owner, you can also change the file belongs to the group at the same time

grammar:

chown [-R] owner name of the file name 
chown [ -R & lt] owner name: name of the file name is a group

Enter the / root directory (~) will bin install.log owner of the account was changed:

[root@www ~] cd ~
[root@www ~]# chown bin install.log
[root@www ~]# ls -l
-rw-r--r--  1 bin  users 68495 Jun 25 08:53 install.log

The install.log owner and group changed back to root:

[root@www ~]# chown root:root install.log
[root@www ~]# ls -l
-rw-r--r--  1 root root 68495 Jun 25 08:53 install.log

3, chmod: change file attributes 9

Linux file attributes There are two settings, one is digital, one is a symbol.

Basic Linux file permissions have nine, respectively, is owner / group / others Three Identities have their own read / write / execute permissions.

To review the data just mentioned above: file permissions characters: "- rwxrwxrwx" nine permissions are three groups of three! Among them, we can use the number to represent each permission, the score table for each of the following rights:

  • r:4
  • w:2
  • x:1

Each identity (owner / group / others) of each of three permission (r / w / x) cumulative score is needed, for example, when permission is: [-rwxrwx ---] score is:

  • owner = rwx = 4+2+1 = 7
  • group = rwx = 4+2+1 = 7
  • others= --- = 0+0+0 = 0

So wait a minute we set to change permissions, the permissions of the file is 770 digital friends! Chmod command syntax permission to change is this:

 chmod [-R] xyz file or directory

Options and parameters:

  • xyz: is the digital rights attribute type just mentioned, the attribute value is added to rwx.
  • -R: recursive (recursive) continues to change, that is, together with all files in subdirectories change

For example, if you want all the permissions are set to enable .bashrc file, then the command is as follows:

[root@www ~]# ls -al .bashrc
-rw-r--r--  1 root root 395 Jul  4 11:45 .bashrc
[root@www ~]# chmod 777 .bashrc
[root@www ~]# ls -al .bashrc
-rwxrwxrwx  1 root root 395 Jul  4 11:45 .bashrc

So, if you want permission to become  -rwxr-xr--  it? Then the fraction permission becomes [4 + 2 + 1] [4 + 0 + 1] [4 + 0 + 0] = 754.

Symbol Type change file permissions

There is also a way to change the permissions from the previous description, we can find, essentially nine privileges are:

  • (1)user
  • (2)group
  • (3)others

Then we can use the  u, g, o  to represent the rights of the Three Identities!

In addition,  A  represents the  All , that is, all identity. Read and write permissions can be written as  r, w, x, i.e. can use the table of view:

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

 

Touch test1 #     // create the test1 file 
# LS -al test1     // View test1 default permissions 
-rw-r - r-- 1 root root 0 Nov 15 10:32 test1 
# chmod U = rwx, G = rx, O = R & lt test1     // modify permission test1 
# LS - Al test1
 -rwxr the root-XR, the root. 1 0 15-Nov 10:32 test1

And if it is you want to remove permissions without changing other permissions already exist it? For example, to remove all of the people of executable permissions, then:

#  chmod  a-x test1
# ls -al test1
-rw-r--r-- 1 root root 0 Nov 15 10:32 test1

Guess you like

Origin www.cnblogs.com/qingmuchuanqi48/p/12064650.html