YouTip LogoYouTip

Python3 Os Lchmod

# Python3.x Python3 os.lchmod() Method [![Image 3: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#) * * * ### Overview The os.lchmod() method is used to modify the permissions of a symbolic link. It is only supported for use on Unix systems. ### Syntax The syntax for the **lchmod()** method is as follows: os.lchmod(path, mode) ### Parameters * **path** -- The file path of the symbolic link to be modified. * **mode** -- Can be one or more of the following, separated by "|": * **stat.S_ISUID:** Set the UID bit. * **stat.S_ISGID:** Set the group ID bit. * **stat.S_ENFMT:** Enforcement action for system file locking. * **stat.S_ISVTX:** Save text and image after execution. * **stat.S_IREAD:** Read permission for the owner. * **stat.S_IWRITE:** Write permission for the owner. * **stat.S_IEXEC:** Execute permission for the owner. * **stat.S_IRWXU:** Read, write, and execute permissions for the owner. * **stat.S_IRUSR:** Read permission for the owner. * **stat.S_IWUSR:** Write permission for the owner. * **stat.S_IXUSR:** Execute permission for the owner. * **stat.S_IRWXG:** Read, write, and execute permissions for the group. * **stat.S_IRGRP:** Read permission for the group. * **stat.S_IWGRP:** Write permission for the group. * **stat.S_IXGRP:** Execute permission for the group. * **stat.S_IRWXO:** Read, write, and execute permissions for others. * **stat.S_IROTH:** Read permission for others. * **stat.S_IWOTH:** Write permission for others. * **stat.S_IXOTH:** Execute permission for others. ### Return Value This method does not return a value. ### Example The following example demonstrates the use of the lchmod() method: #!/usr/bin/python3import os, sys # open file path = "/var/www/html/foo.txt" fd = os.open( path, os.O_RDWR|os.O_CREAT )# Close file os.close( fd )# Modify file permissions# Set the file to be executable by group using os.lchmod( path, stat.S_IXGRP)# Set the file to be writable by other users using os.lchmod("/tmp/foo.txt", stat.S_IWOTH)print ("Permission modification successful!!") Executing the above program outputs the following result: Permission modification successful!! [![Image 4: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#)
← Python3 Os LinkPython3 Os Isatty β†’