Hello, I'm trying to run the following program, but I'm getting an error. My OS is Linux Ubuntu 18.04 LTS and the IDE is IDLE.
#!/usr/bin/python3.8 import os, sys # Open a file path = "/home/user/Desktop/Programming/Python/var/www/html/foo.txt" fd = os.open(path, os.O_RDWR|os.O_CREAT) # Close opened file os.close( fd ) # Now change the file ownership # Set a file owner id os.lchown( path, 500, -1) # Set a file group ID os.lchown( path, -1, 500) print("Changed ownership successfully!!") # "/home/user/Desktop/Programming/Python/var/www/html/foo.txt"The error is:
Error:Traceback (most recent call last):
File "/home/user/Desktop/Programming/Python/Os lchown method.py", line 10, in <module>
os.lchown( path, 500, -1)
PermissionError: [Errno 1] Operation not permitted: '/home/user/Desktop/Programming/Python/var/www/html/foo.txt'