Linux self-study journey-basic commands (chown and chgrp)

Linux self-study tour-basic commands (commands to change the owner and group)


Preface

1. In the previous section, we summarized the role of basic permission bits for files, mainly about the permission bits between ordinary files and directory files and their differences. If you haven’t read it, please click the link below to watch it: Basic The role of permission bits

2. In this section, we continue to return to the commands. Let’s talk about two commands that can operate on the permission bits. One can modify the file owner and the other can modify the group of the file.


Tip: The following is the content of this article

One, chown command

We know that chmod is a permission mode that can modify the permission bits, so is there a command that can modify the file owner in our Centos? The answer is of course yes, this is our chown command, chown command can modify the file owner and group

  • Command name: chown
  • The full name of the command: change file owner and group
  • Location: /bin/chown
  • Execution authority: all users
  • Function description: modify file owner or group
命令格式
chown [选项] 所有者:所属组 文件名称
-R:递归修改,也就是给目录下所有文件都修改权限

Let's give two examples:

(只修改所有者)
[root@localhost ceshi]# ls -lh 
总用量 0
-rw-r--r-- 1 root root 0 1月  27 09:11 a.txt
[root@localhost ceshi]# 
[root@localhost ceshi]# chown snljh a.txt 
[root@localhost ceshi]# ls -lh
总用量 0
-rw-r--r-- 1 snljh root 0 1月  27 09:11 a.txt
[root@localhost ceshi]# 

(如上,我a.txt这个文件本来所有者是root,但是我通过chown这个命令将该文件的所
有者变为snljh这个用户)
(修改所有者和所属组)
[root@localhost ceshi]# ls -lh
总用量 0
-rw-r--r-- 1 snljh root 0 1月  27 09:11 a.txt
[root@localhost ceshi]# chown snl:snl a.txt 
[root@localhost ceshi]# 
[root@localhost ceshi]# ls -lh
总用量 0
-rw-r--r-- 1 snl snl 0 1月  27 09:11 a.txt
[root@localhost ceshi]# 

(还是刚刚那个文件,我用chown后面接要修改的所有者和所属组的方式
修改了我a.txt这个文件的所有者和所属组)

Two, chgrp command

The main function of the chgrp command is to modify the group to which a file belongs . In fact, let’s say, the first chown command can modify both of them. It’s almost the same if you only remember one, but since we have this command, we still have to Learn about.

  • Command name: chgrp
  • The full name of the command: change group ownership
  • Location: /bin/chgrp
  • Execution authority: all users
  • Function description: modify the file belonging group
命令格式
chgrp 所属组 文件名称

for example:

[root@localhost ceshi]# ls -lh 
总用量 0
-rw-r--r-- 1 snl snl 0 1月  27 09:11 a.txt
[root@localhost ceshi]# 
[root@localhost ceshi]# chgrp snljh a.txt 
[root@localhost ceshi]# 
[root@localhost ceshi]# ls -lh
总用量 0
-rw-r--r-- 1 snl snljh 0 1月  27 09:11 a.txt
[root@localhost ceshi]# 

(如上,我a.txt这个文件的所属组本来是snl的,我利用chgrp这个命令
将文件的所属组变成了snljh)

to sum up

In this section, we have finished { 1. Command to modify the file owner and group: chown 2. Command to modify the group to which the file belongs: chgrp } In the next section, we continue to talk about permissions



This is Jiehua, see you next time!

Guess you like

Origin blog.csdn.net/qq313088385/article/details/113246827