Change the user group to which the chgrp file belongs. you can use chgrp to change the user group. This command is short for changegroup (change user group. This makes it easy to remember. However, remember that the name of the user group to be changed must exist in/etc/group. Otherwise, an error is displayed. Assume that you have logged on to FC4 as the root user, so there is an install. log file in your home directory. how can you change the user group of this file? Suppose you already know
Change the user group to which the chgrp belongs.
It is easy to change the user group of a file. use chgrp directly. This command is short for change group. This makes it easy to remember. However, remember that the name of the user group to be changed must exist in/etc/group. Otherwise, an error is displayed.
Assume that you have logged on to FC4 as the root user, so there is an install. log file in your home directory. how can you change the user group of this file? Suppose you already know that there is a user group named users in/etc/group, but the user group name testing does not exist in/etc/group, what happens when the user group is changed to users and testing?
[Root @ linux ~] # Chgrp [-R] dirname/filename... parameter:-R: implements recursive (recursive) changes, that is, all files and directories under the subdirectory are updated to the user group. It is often used to change a directory. Example: [root @ linux ~] # Chgrp users install. log [root @ linux ~] # Ls-l-rw-r -- 1 root users 68495 Jun 25 install. log [root @ linux ~] # Chgrp testing install. logchgrp: invalid group name 'testing' <= error message ~ The user group name cannot be found ~
Found? The user group of the file is changed to users, but an error occurs when the user group is changed to testing. Note: If an error message is displayed, check the content of the error message. How to change the owner of a file, chown? Very simple. Since the change user group is a change group, the change owner is the change owner ). This is the purpose of the chown command. Note that the user name must be logged in the/etc/passwd file. Chown has many purposes. you can also directly modify the user group name. In addition, if you want to change the owner of all subdirectories or files under the Directory, add the-R parameter directly. Let's take a look at the syntax and examples:
[Root @ linux ~] # Chown [-R] account name file or directory [root @ linux ~] # Chown [-R] account name: User group name file or directory parameter:-R: for recursive (recursive) continuous changes, that is, all files and directories under the subdirectories are updated to the user group. It is often used to change a directory. Example: [root @ linux ~] # Chown bin install. log [root @ linux ~] # Ls-l-rw-r -- 1 bin users 68495 Jun 25 install. log [root @ linux ~] # Chown root: root install. log [root @ linux ~] # Ls-l-rw-r -- 1 root 68495 Jun 25 08:53 install. log
We know how to change the user group and owner of a file. When should we use chown or chgrp? Maybe you think it's strange? Yes, sometimes it is necessary to change the owner of the file. The most common example is to use the simplest cp to explain when copying the file to another person:
Suppose you want to copy the. bashrc file to. bashrc_test today and give it to the bin user. you can do this:
[root@linux ~]# cp .bashrc .bashrc_test[root@linux ~]# ls -al .bashrc*-rw-r--r-- 1 root root 395 Jul 4 11:45 .bashrc-rw-r--r-- 1 root root 395 Jul 13 11:31 .bashrc_test |
What should I do ?. Bashrc_test still belongs to the root user. as a result, even if the file is given to the bin user, it still cannot be modified (you can see the attributes). Therefore, you must modify the owner and user group of the file.