Linux Server Programming: Chown () function, Chown command

Source: Internet
Author: User
Tags function definition

1. Dependent header Files

#include <unistd.h>

2. Function definition:

Change the ownership relationship of the file by passing in path, and if he is a symbolic link, track it

int chown (const char *path, uid_t owner, gid_t Group);

Modification of all user groups, etc. by means of file description
int fchown (int fd, uid_t owner, gid_t Group);

Unlike Chown, it does not track symbolic links
int Lchown (const char *path, uid_t owner, gid_t Group);


Function Description:

A: The system calls this function to change the owner and owning group of a file

B: Once successful, return 0, once wrong, will return-1,

3. Case Description:

Use of the 4.chown command

Purpose: Change the owner or group of the file. Commands are composed of the word change owner

Examples of Use:

A: Change the owner of a file

Chown Toto PROGRAM.C

Change the owner of the file program.c to Toto. As an owner, Toto can use the chmod command to allow or deny access to other users PROGRAM.C

B: Change the owner of the directory:

Chown-r JOHN:BUILD/TMP/SRC

Change the owner and group of all files in directory/tmp/src to user John and group build

-R recursively changes the owner of the specified directory and all subdirectories and files under it

-V shows the work done by the Chown command




Linux Server Programming: Chown () function, Chown command

Related Article

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.