OS. chmod () method this method updates the path or File Permission In numeric mode. This mode can take one of the following values or bitwise OR operation combinations:
- Stat. s_isuid: Set User ID on execution.
- Stat. s_isgid: Set Group ID on execution.
- Stat. s_enfmt: record locking enforced.
- Stat. s_isvtx: save text image after execution.
- Stat. s_iread: Read by owner.
- Stat. s_iwrite: write by owner.
- Stat. s_iexec: Execute by owner.
- Stat. s_irwxu: read, write, and execute by owner.
- Stat. s_irusr: Read by owner.
- Stat. s_iwusr: write by owner.
- Stat. s_ixusr: Execute by owner.
- Stat. s_irwxg: read, write, and execute by group.
- Stat. s_irgrp: Read by group.
- Stat. s_iwgrp: write by group.
- Stat. s_ixgrp: Execute by group.
- Stat. s_irwxo: read, write, and execute by others.
- Stat. s_iroth: Read by others.
- Stat. s_iwoth: write by others.
- Stat. s_ixoth: Execute by others.
Syntax:
OS. chmod (path, mode );
Parameters:
- Path: this is the path for which mode wocould be set.
- Mode: this may take one of the above mentioned values or bitwise ored combinations of them:
Example 1:
#!/usr/bin/python
import os, sys, stat
# Assuming /tmp/foo.txt exists, Set a file execute by the group.
os.chmod("/tmp/foo.txt", stat.S_IXGRP)
# Set a file write by others.
os.chmod("/tmp/foo.txt", stat.S_IWOTH)
print "Changed mode successfully!!"
This produces following result:
Changed mode successfully!!
os.chmod("/tmp/foo.txt", stat.S_IRWXU|stat.S_IRGRP|stat.S_IROTH) # mode:777