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