Skip to content

Instantly share code, notes, and snippets.

@igniteflow
Last active October 9, 2024 08:05
Show Gist options
  • Save igniteflow/4474040 to your computer and use it in GitHub Desktop.
Save igniteflow/4474040 to your computer and use it in GitHub Desktop.
Create a folder and set user:group with Python's os module
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
Copy link

ghost commented Feb 13, 2018

I think the second call to pwd.getpwnam should be .pw_gid not .pw_uid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment