YouTip LogoYouTip

Python3 Os Chown

# Python3.x Python3 os.chown() Method [![Image 3: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#) * * * ### Overview The os.chown() method is used to change the owner of a file. If you do not want to modify it, you can set it to -1. You need superuser privileges to perform permission modification operations. It is only supported for use on Unix. ### Syntax The syntax format for the **chown()** method is as follows: os.chown(path, uid, gid); ### Parameters * **path** -- The file path for which to set permissions. * **uid** -- The user ID of the owner. * **gid** -- The group ID of the owner. ### Return Value This method does not return a value. ### Example The following example demonstrates the use of the chown() method: #!/usr/bin/python3import os, sys # Assume the /tmp/foo.txt file exists. # Set the owner ID to 100 os.chown("/tmp/foo.txt", 100, -1)print ("Permissions modified successfully!!") Executing the above program outputs the following result: Permissions modified successfully!! [![Image 4: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#)
← Python3 Os ClosePython3 Os Chown β†’