[Reprint] linux user group for changing the file folder (chgrp)

Source: Internet
Author: User

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...
Parameters:
-R: Perform recursive changes, that is, all the files and directories under the subdirectory.
Are updated to this 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. Log
Chgrp: 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.
Change the file owner, chown
So how to change the owner of a file? 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
Parameters:
-R: Perform recursive changes, that is, all the files and directories under the subdirectory.
Are updated to this 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:
[Root @ Linux ~] # Cp
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.