Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MorningLightMountain713/2188098ab14d25e70b7ea9e8bc9b0f8d to your computer and use it in GitHub Desktop.
Save MorningLightMountain713/2188098ab14d25e70b7ea9e8bc9b0f8d 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment