Python os.chown() Method
Example
Change the owner and group id of a specified path:
#Import os Library
import os
#change the owner id and group id of file
os.chown('./file.txt', 100, 2000)
Run Code »
Definition and Usage
The os.chown()
method changes the owner and group id of
a specified path to the specified numeric owner id and group id.
Note: Available only on UNIX platforms. This method is used by Superuser and privileged user.
Syntax
os.chown(path, uid , gid, dir_fd, follow_symlinks)
Parameter Values
Parameter | Description |
---|---|
path | Required. Sets the path of the file/directory on which owner id and group id need to be changed |
uid | Required. An integer value representing the owner id to be set for the path |
gid | Required. An integer value representing the group id to be set for the path. To leave one of the ids unchanged, set it to -1 |
dir_fd | Optional. If NONE, the path will be relative to the directory. Default value is None |
follow_symlinks | Optional. Default value is TRUE. Set it to FALSE to not follow symlinks |
Technical Details
Return Value: | None |
---|---|
Python Version: | 2.6 |
Change Log: | 3.3: Support for specifying path as an open file descriptor, and added the
dir_fd and follow_symlinks parameters. 3.6: Accepts a path-like object. |