[SOLVED chattr] Unable to Fix permissions for Files and Folders using root
Ever faced issue operation not permitted error when changing files and folders even with root/sudo? This could be an issue because of file and folder attributes are set to unchangeable by the system or some malware.
[root@basezap web]# rm -rf testing/rm: cannot remove testing: Operation not permitted
In such cases, chmod and chown also throw “Operation not permitted” error with the files and folders. This issue occurs when attributes are set to the files and folders. We will fix this problem using ‘chattr’ Linux Command.
chattr (Change Attribute) is a Linux command line utility that is used to set/unset certain attributes to a file. We will discuss its operator below.
- + : Adds the attribute to the existing attribute of the files.
- – : Removes the attribute to the existing attribute of the files.
- = : Keep the existing attributes that the files have.
- i : A file with ‘i‘ attribute, cannot be modified which means no renaming, no symbolic link creation, no execution, no writable, only superuser can unset the attribute.
- R : Recusively
Setting attribute to a file
chattr +i testfile.txt
Removing attribute to a file
chattr -i testfile.txt
Setting attribute to files and folders recursively
chattr -R +i testfile.txt
Removing attribute to files and folders recursively
chattr -R -i testfile.txt
With this basic commands Operation, not permitted will be resolved.