I. Users and user groups
owner (owner): Generally the creator of the file, who created the file, naturally becomes the owner of the file, each file owner (master) has and only one. You can see the owner of the file with the LL command.
owning Group (genus): When a user creates a file, the group of the file is the group that the user is in, a user can belong to multiple groups but only one primary group, with the LL command to see all the groups of the file.
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9C/CA/wKioL1l2AFvRNnmKAAA4YEkfkP4537.png "title=" 123 " alt= "Wkiol1l2afvrnnmkaaa4yekfkp4537.png"/>
Other People : Except for the owner of the file and a user other than the owning group, the other users of the system are others of the file. For example, the creation of two users Tom and jerry,tom relative to the file created by Jerry is someone else.
ii.. File Permissions
Linux system is a typical multi-user system, different users in different positions, with different permissions. In order to protect the security of the system, the Linux system has different requirements for different users to access the same file (including directory files).
[[email protected] app] #ll F1 #使用ll或者ls-l command to display the properties of a file and the owner and the group-RW-RWXR--. 1 root root ten Jul 21:05 F1
instance, the first field represents the permissions that the F1 file has (-rw-rwxr--.), what do these bits mean? The first 10 characters represent what different users can do with the file, and the last "." Represents the ACL permissions (Access control list).
The first character represents a file type
D: Represents a catalog file
-: Indicates normal file
L: Indicates a linked file
C: Character files, such as/dev/zero
B: Represents a block file, such as/dev/sda
In the following characters, a group of three and a combination of three parameters are [rwx]. Where [r] represents a readable (read) number represented as 4, [W] for writable (write) is represented by a number of 2, [x] represents the executable (execute) is represented by a number of 1. Note that the location of the three permissions does not change, and if there is no permission, a minus sign "-" will appear instead. Detailed description of the following table
|
file type |
Owner (U) |
Group (g) |
Other People (O) |
bit |
0 |
< Span style= "Font-family:impact, Chicago;" > 1 2 3 |
4 5 6 |
7 8 9 |
permissions |
- |
r w - |
r w x |
r - - |
Meaning |
Normal file |
Read, write, no execution |
Read, Write, execute |
Read, no write permission, no execution |
The 10 bits from left to right represent:
-
< Span style= "Font-family:impact, Chicago;" The No. 0 bit determines the file type
-
第1-3位 determines that the owner of the file has permissions to the file
-
第4-6位 determine the genus Group (owner of the same group of users) has permission to the file
-
第7-9位 Determine the permissions that other users have on the file
-
where the 1th, 4, 7 bits represent read permissions, if the "R" character is indicated, then there is read permission, if the "-" character is indicated, then there is no Read permission, 2nd, 5, 8 bits for write permission, if the "W" character is indicated, there is write permission, if the "-" character means no write permission; The 9-bit represents the executable permission, and if it is represented by an "x" character, there is an EXECUTE permission, and if the "-" character is represented, then the permission is not executed.
-
each field after the permission is table Example: number of links, owner, genus Group, file size, file latest modification time, filename
Third, file property modification
[[Email protected] ~]#[[email protected] ~] #ll-D music/drwxr-xr-x. 2 root root 6 Jul 4 08:29 music/
For a file, it has a specific owner, that is, the user who owns the file. At the same time, in a Linux system, users are categorized by group, and one user belongs to one or more groups. Users other than the file owner can be divided into the same group of users and other users as the file owner. Therefore, the Linux system provides different file access rights by file owner, file group, and other users. In the above example, the Music file is a directory file, both the master and the group are root, the owner has a readable, writable, executable permission, and the other users of the group have readable and executable permissions; Other users also have readable and executable permissions. For root users, in general, the permissions of the file do not work (root is the god of Linux, in charge of everything).
Format
chown [Options] [owner, owner: Group] FILE
Instance
[[email protected] tmp] #ll profile-rw-r--r--. 1 root root 1795 Nov 6 profile #profile文件的属主和属组都是root [[email protected] tmp] #chown Vincent profile #改变profile的属主为v Incent[[email protected] tmp] #ll profile-rw-r--r--. 1 Vincent Root 1795 6 * Profile # Owner modified to Vincent[[email protected] tmp] #chown root:vincent profile #同时修改属主为root, group For Vincent[[email protected] tmp] #ll profile-rw-r--r--. 1 root Vincent 1795 Nov 6 Profile #属主属组被修改为root和vincent [[email protected] tmp]#
Note: You can not only use colon segmentation (root:vincent), but also use dot Division (root.vincent) when modifying both the owner and the group.
In addition to the Chown can change the group, there is also a command to modify the genus Group (CHGRP)
Format
CHGRP [-R] belongs to group name FILE
Instance
[[email protected] tmp] #ll profile #查看文件属组为 root-rw-r--r--. 1 Vincent Root 1795 Nov 6 Profile[[email protected] tmp] #chgrp Vincent profile #修改属组为vincent [[email protected] tmp ] #ll profile-rw-r--r--. 1 Vincent Vincent 1795 Nov 6 profile #修改成功, group changed to Vincent
Description:-R indicates a recursive change of the genus Group, that is, when changing the genus of a directory file, if you add the-r parameter, the group of all files under that directory will change
The permission bit of the file has 9 bits, which is a group of 3 bits, which indicates the permissions of the owner, the group, and others respectively. Each set of permissions is read/write/execute (readable/writable/executable) from left to right
There are two ways to express file permissions in Linux: Mode and digital. Mode method will belong to the main, belong to the group, the other people with the letter U, G, O, respectively, the number of numbers 4, 2, one to express the read, write, execute permissions, each identity (Owner/group/others) the respective three permissions (r/w/x) score is required to accumulate.
Chmod--> Mode method
Format
chmod [u=,g=,o=,ug=,a=] [r,w,x,rw,rx,wx] FILE #修改一类用户的权限chmod [U+,u-,...] [R,w,x,...] File #修改一类用户某位的或某些位的权限chmod--reference=rfile file #修改FILE文件的权限同rfile文件
instance
[[email protected] tmp]#[[email protected] tmp] #ll profile -rw---XR--. 1 vincent vincent 1795 nov 6 2016 profile[[email protected] tmp]# chmod g+r profile && ll profile # Add r permissions to a genus group-rw-r-xr--. 1 vincent vincent 1795 nov 6 2016 profile[[email &NBSP;PROTECTED]&NBSP;TMP] #chmod o+wr profile && ll profile #给其他人添加rw权限-rw-r-xrw-. 1 vincent vincent 1795 nov 6 2016 profile [[Email protected] tmp] #chmod u=x profile && ll profile #将属主权限设置为x, overwrite old permissions---xr-xrw-. 1 vincent vincent 1795 nov 6 2016 profile[ [Email protected] tmp] #touch 1.txt && ll 1.txt #创建一个新文件 for the following experiment-rw-r--r--. 1 root root 0 jul 27 17:50 1.txt[[email protected] &NBSP;TMP] #chmod --reference=1.txt profile && ll profile -rw-r--r--. 1 vincent vincent 1795 Nov 6 2016 profile #将权限设为同1. txt permissions [[email protected] tmp]#
Description:"&&" means that the handle before "&&" is executed before "&&" is executed, and the previous permission is overwritten when the permission is set with "=".
Chmod--> Digital Method
Permission Representation method
Permissions binary representation octal means--- 000 0--x 001 1-w- 010 2-wx 011 3r-- 100 4r-x 101 5rw- 110 6rwx 111 7rwxr-xrw- 111 101 011 756
Format
chmod [-R] XYZ File/dir ... # XYZ represents the rights of the owner, the group, and others respectively
Instance
[[Email protected] app]#[[email protected] app] #ll &NBSP;MESSAGES&NBSP;-RW-------. 1 root root 2914301 Jul 26 08:24 messages # Messages file permissions for 600[[email protected] app] #chmod 777 messages && ll messages #设置所有用户权限为读写执行-rwxrwxrwx. 1 root root 2914301 jul 26 08:24 messages[[email protected] app] #chmod 755 messages && ll messages #去除属组和其他人的写权限-rwxr-xr-x. 1 root root 2914301 Jul 26 08:24 messages[[email protected] app] #chmod 055 messages & & ll messages ----r-xr-x. 1 root root 2914301 jul 26 08:24 messages #设置权限为055 [[email protected] app]#
Description: for the folder (directory), the system default permission is 777, the system default permissions for the file is 666; This design guarantees the security of Linux system files. In addition to these basic attributes, the file has other permissions (SUID, SGID, Stikty), and ACLs (access control lists), which will be provided for you in the future, so stay tuned!
650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0076.gif "alt=" J_0076.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0076.gif "alt=" J_0076.gif "/> Thank you for reading! (650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0076.gif "alt=" J_0076.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0076.gif "alt=" J_0076.gif "/>"
This article is from the "Vincent" blog, make sure to keep this source http://vinsent.blog.51cto.com/13116656/1951572
Basic properties of files in Linux