Python | shutil.copymode() method Last Updated : 04 Jul, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 the process of copying and removal of files and directories.shutil.copymode() method in Python is used to copy the permission bits from the given source path to given destination path. The shutil.copymode() method does not affect the file content or owner and group information. Syntax: shutil.copymode(source, destination, *, follow_symlinks = True)Parameter: source: A string representing the path of the source file. destination: A string representing the path of the destination file. follow_symlinks (optional) : The default value of this parameter is True. If it is False and source and destination both refers to a symbolic link then the shutil.copymode() method will try to modify the mode of destination (which is a symbolic link ) itself rather than the file it points to.Note: The '*' in parameter list indicates that all following parameters (Here in our case 'follow_symlinks') are keyword-only parameters and they can be provided using their name, not as positional parameter.Return Type: This method does not return any value. Code: Use of shutil.copymode() method to copy permission bits from source path to destination path Python3 # Python program to explain shutil.copymode() method # importing os module import os # importing shutil module import shutil # Source file path src = "/home/ihritik/Desktop/sam3.pl" # Destination file path dest = "/home/ihritik/Desktop/encry.py" # Print the permission bits # of source and destination path # As we know, st_mode attribute # of ‘stat_result’ object returned # by os.stat() method is an integer # which represents file type and # file mode bits (permissions) # So, here integere is converted into octal form # to get typical octal permissions. # Last 3 digit represents the permission bits # and rest digits represents the file type print("Before using shutil.copymode() method:") print("Permission bits of source:", oct(os.stat(src).st_mode)[-3:]) print("Permission bits of destination:", oct(os.stat(dest).st_mode)[-3:]) # Copy the permission bits # from source to destination shutil.copymode(src, dest) # Print the permission bits # of destination path print("\nAfter using shutil.copymode() method:") print("Permission bits of destination:", oct(os.stat(dest).st_mode)[-3:]) Output: Before using shutil.copymode() method: Permission bits of source: 664 Permission bits of destination: 777 After using shutil.copymode() method: Permission bits of destination: 664 Reference: https://docs.python.org/3/library/shutil.html Comment More infoAdvertise with us Next Article shutil.copytree() method - Python I ihritik Follow Improve Article Tags : Python python-utility Practice Tags : python Similar Reads Python | shutil.copy() method Python3 # Python program to explain shutil.copy() method # importing shutil module import shutil # Source path source = "/home/User/Documents/file.txt" # Destination path destination = "/home/User/Documents/file.txt" # Copy the content of # source to destination try: shutil.copy( 5 min read Python | shutil.copy2() method 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 copying and removal of files and directories.shutil.copy2() method in Python is used to copy the co 4 min read Python | shutil.copyfile() method Shutil module in Python helps automate the process of copying and removing files and directories. It comes under Pythonâs standard utility modules. Shutil(short for shell utility) module also provides many functions of high-level operations on files and collections of files. What is Shutil.copyfile 4 min read shutil.copytree() method - Python shutil.copytree() method in Python is used to recursively copy an entire directory tree from a source to a destination. It copies all the contents, including files and subdirectories, preserving the directory structure.Syntaxshutil.copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, 3 min read Python | shutil.copystat() method 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 copying and removal of files and directories.shutil.copystat() method in Python is used to copy the 3 min read Python | shutil.copyfileobj() method 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.copyfileobj() method in Python is used to copy 2 min read Like