How to Delete Files That Can’t be Deleted by Root

2017/05/05

I had been testing to build WordPress on my VPS. After a successful experiment, I decided to restore the previous snapshot and make another clean installation with fewer mistakes.

And that’s when I noticed something strange. Several files created in the last build hadn’t been deleted after the restoration…totally unacceptable!

I tried to use rm -rf to delete them at first, but failed with an “operation not permitted” message being returned. Jesus, if the root couldn’t do it, who else can?

But I wouldn’t give up easily without googling first 😂. Fortunately, someone told me it was due to an “i” attribute attached to the files that they became indestructible.However, the attribute could be removed by implementing the command chattr -i example.file (and chattr +i example.file to add and protect again)

Chattr is not included in some distributionsd, so you may need to get it first.

Also, there is another related command ‘lsattr’ which can be used to list the “i-attributed” file in your working directory.

Reference: How to install chattr on Debian to make files immutable: NetDip