Last active
October 9, 2024 08:05
-
-
Save igniteflow/4474040 to your computer and use it in GitHub Desktop.
Create a folder and set user:group with Python's os module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pwd | |
file_path = '/tmp/example' | |
if not os.path.exists(file_path): | |
os.makedirs(file_path) # creates with default perms 0777 | |
uid, gid = pwd.getpwnam('root').pw_uid, pwd.getpwnam('www-data').pw_uid | |
os.chown(file_path, uid, gid) # set user:group as root:www-data | |
# go check with ls -lah /tmp/example |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the second call to pwd.getpwnam should be .pw_gid not .pw_uid