VOOZH about

URL: https://www.geeksforgeeks.org/python/python-shutil-chown-method/

⇱ Python | shutil.chown() method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python | shutil.chown() method

Last Updated : 12 Oct, 2021

Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating process of chowning and removal of files and directories.
shutil.chown() method in Python is used to change the owner and /or group of the specified path. 
 

Syntax: shutil.chown(path, user = None, group = None)
Parameters: 
path: A string value representing a valid path. 
user: A string value representing a system user 
group: A string value representing a group 
user and group can be also given by user id (uid) and group id (gid) respectively.
Return Type: This method does not return any value. 
 


Code #1: Use of shutil.chown() method to change owner and group of the specified path 
 


Output: 
Current owner and group of the specified path
Owner: root
Group: root

Owner and group changed
Current owner: ihritik
Current group: ihritik

Only group changed
Current owner: ihritik
Current group: root

 

Code #2: Use of shutil.chown() method 
 


Output: 
Current owner and group of the specified path
Owner: ihritik
Group: ihritik

Owner and group changed
Current owner: root
Current group: root

 

Reference: https://docs.python.org/3/library/shutil.html
 

Comment
Article Tags: