I’m not simply talking about deleting files in Linux that the user cannot delete. I’m talking about files that root cannot delete either!
I am playing around with a great little operating system called Porteus (website here). It base around Slackware (the oldest Linux distro) and is both amazingly fast and incredibly small. But I digress. But I came across this problem during my experimentation with Porteus.
Porteus installs on a USB stick and (as you do) I decided to burn it down and re-install. There are two directories one called Porteus and the other (unsurprising) called boot.
For the life of me I could not delete the boot directory. So I looked in it and then into one of its subdirectories syslinux. Here all but one file could, after fiddling about, be deleted by root. But there was one that could not. Namely ldlinux.sys.
Here’s what this directory looks like in a terminal.
In directory syslinux (as you can see) almost all files by default are read-only. This can be fixed by root changing that to rw and then deleting.
BUT… There is one that won’t go and outstays its welcome. ldlinux.sys.
If you look ldlinux.sys is read-only for root and nobody else has access at all. Not even the group – which is root!
Even as root you cannot change the permissions on this file using chmod! It won’t go.
I Googled this for a while and came across this post on stackexchange (here)
Basically the file has been made immutable. Which means it cannot be changed/deleted/modified by anyone. Including root. Deleting files with the immutable bit set is a no-no.
IBM describe it as so on one of their products: (here)
“An immutable file cannot be changed or renamed. An appendOnly file allows append operations, but not delete, modify, or rename operations.”
So basically, you cannot delete the file. Unless you remove the immutability first.
Anyway what you need to do is:
chattr -i -a filename
The -i removes the immutability and the -a removes the append-only flag (if there is one)
Either way you can now do a sudo chmod 777 filename (or sudo
chmod ugo+w) and then delete it with sudo rm filename.
Hope that helps. Here’s the rest of my Linux/Ubuntu howto’s