
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
How to change the user and group permissions for a directory using Python?
You can change the owner of a file or a directory using the pwd, grp and os modules. The uid module is used to get the uid from user name, grp to get gid group name string and os to change the owner:
Example
import pwd import grp import os uid = pwd.getpwnam("my_name").pw_uid gid = grp.getgrnam("my_group").gr_gid path = 'my_folder' os.chown(path, uid, gid)
- Related Articles
- How to check the permissions of a directory using Python?
- How to find the real user home directory using Python?
- How to change the permission of a directory using Python?
- How to change the owner of a directory using Python?
- How to change current directory using Python?
- How to change file permissions in Python?
- How to Change the Default Home Directory of a User on Linux?
- How to check the permissions of a file using Python?
- How to create a directory using Python?
- How to remove a directory using Python?
- How to change user agent for Selenium driver?
- How to add the user to the local Administrators group using PowerShell?
- How to change the password in MongoDB for existing user?
- How to change the local user account password using PowerShell?
- How to know/change current directory in Python shell?

Advertisements