Group __linux of Linux modification files

Source: Internet
Author: User
Tags filegroup file permissions
How to change the owner and group of a file under Linux >

Learn to change the owner and group ownership of files and directories using the Chown and CHGRP commands. This tuxfile will give you more insight if you already have the knowledge of file permissions and the basics of ownership.

<chown-Change the owner of the file >

With the Chown command you can change the owner and group of a file or directory. However, please note that only the root user and the file owner can change.

To set the owner of a file:
$ chown Username Somefile

After giving this command, the new owner of the file called Somefile is username. The group owner of the file does not change. You can also give the user a digital ID instead of the user name here.

You can also set the file group at the same time. If your username is followed by a colon and a group name, the filegroup will also be changed.
$ chown Username:usergroup somefile

Given this command, the new owner of Somefile is a user named username and a group called UserGroup.

You can also set the owner of the directory exactly the same way.
$ chown Username Somedir

Note After giving this command, only the owner of the directory will change. All of the files in the directory will not change.

To set up the directory and all of the files in it, you will need the-r option:
$ chown-r Username Somedir

Here, R stands for recursion, because this command changes the ownership of the directory and its contents, all at one level. After this command is executed, the username username will be the owner of the directory Somedir, and the user name of all files under this directory should be username.

Tell me what happened:

$ chown-v Username Somefile
Changed ownership of ' somefile ' to username

Here, V represents the long. If you use the-v option, Chown will list what he did (or did not do) with the file. This verbose pattern is useful when you change the ownership of several files at once. For example, when you change layers, the following occurs:

$ CHOWN-RV Username Somedir
Changed ownership of ' somedir/' to username
Changed ownership of ' somedir/boringfile ' to username
Changed ownership of ' somedir/somefile ' to username

As you can see, Chown is a great reminder of what you've done with each file.

<CHGRP-Change file group ownership >

As an extension of chown, you can also use the CHGRP command to change a file or directory group. Again, you must be the root user or the file owner to change the ownership of the group. Chgrp and chown work in very similar ways, of course, except for the user group of the file instead of the owner.
$ chgrp UserGroup somefile

After this command is executed, the file somefile will be usergroup by a user group. Although the filegroup was changed to UserGroup, the file owner was previously. The CHGRP options used below are the same as the chown. So for example, the-R and-V options will have the same effect as in Chown

$ CHGRP-RV UserGroup Somedir
Changed group of ' somedir/' to UserGroup
Changed group of ' Somedir/boringfile ' to UserGroup
Changed group of ' Somedir/somefile ' to UserGroup

Chown better prompt you to change each 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.