related articles
Linux: df, du capacity query command
Linux: Disk status observation commands lsblk, blkid
chgrp
Usage: chgrp [-R] groupname dirname/filename
The -R option means recursive change, that is, if the target object is a directory, all files and directories under the directory will be changed at the same time.
This command is an abbreviation of change group. Its function is to change the user group to which a file or directory belongs, but it should be noted that this user group must have been created, that is, it must already exist in the /etc/group file, otherwise an error will be reported.
This command can be used by the file owner and root, but it should be noted that the file owner cannot use this command to change the user group to root, and the system will report an error: "chgrp: changing the group of "ch01": operation not allowed."
The example is as follows
chown
用法:chown [-R] username dirname/filename
或者:chown [-R] username:groupname dirname/filename
The -R option means recursive change, that is, if the target object is a directory, all files and directories under the directory will be changed at the same time.
This command is the abbreviation of change owner. Its function is to change the owner of a file, but it should be noted that the owner (user) must already exist in the system, that is, in the file /etc/passwd, otherwise an error will be reported .
Pay attention to the second usage of the second command. This command can also modify the file user group at the same time or only modify the file user group. Use the : symbol to separate it. Note that the restrictions on user group modification here are the same as chgrp.
This command can only be used by root, even the file owner cannot transfer the file to another user.
The example is as follows
chmod
There are two broad categories of usage for this command. The first category is digital permission modification, and the second category is symbolic permission modification.
Digital type permission modification
There are nine basic permissions for a file or directory in Linux, namely the owner, the user group to which it belongs, and the respective read (read), write (write), and execute (execute) permissions of other people, represented by r, w, and x respectively. , For example: -rwxr--r--, means that the owner of this file can read, write, and execute, and the members of the user group and others can only read it. At this time, we can use numbers to represent the three permissions of r, w, and x. The comparison is
r:4 w:2 x:1,这时rwxr--r--用数字表示为744。
用法:chmod [-R] 数字类型 dirname/filename
-R选项表示递归更改,即如果目标对象是目录,目录下的所有文件和目录都会同时被更改权限。
例子如下
符号类型权限修改
直接使用u、g、o代表三种身份,此外,a表示all即全部的身份。再使用r、w、x表示三种权限,+\-\=分别表示加入,移除和设置。
用法:chmod u/g/o +/-/=(可以多项,使用,隔开,不能有空格) r/w/x(可以多项,顺序任意) dirname/filename
例子如下
这种更改权限的方式好处在于能够通过+、-来增加或减少一个身份的某个权限而不影响这个身份的其它权限,也无需知道这个用户原本的权限,如果是使用数字类型权限修改,那么在增加或减少某个身份的权限时,需要先知道原本的权限,才好使用数字指定权限。