How to delete file with no write permissions for any user?
Solution 1
If you can't take ownership of them with the command:
sudo chown "${USER}" filename
And you can't delete them with the command:
sudo rm filename
Then you need to check if you can write at all to the partition.
If you can change other files on the partition, but not those files, then you probably have one of the following:
- Files with the immutable flag set
- Filesystem errors
- Read-only overlay-fs
- Some weird corrupted ACL
or a kernel thread or a root-kit may be blocking writes to the files.
Solution 2
Removing a file means changing the directory containing them. The file's permissions (and its ownership, for that matter) are inconsequential.
So, if you have write permissions to the containing directory, a simple rm
should work.
If you do not, you will have to chmod +w .
first.
Related videos on Youtube
Dhara
Updated on September 18, 2022Comments
-
Dhara over 1 year
I find myself in a strange situation where a script wrote files with the following permissions:
-r-------- 1 user1 user1 file1 Dec 24 14:53 -r-------- 1 user1 user1 file2 Dec 24 14:54 -r-------- 1 user1 user1 file3 Dec 24 14:55
How do I remove these files? I can't change the permissions of the files with chmod [neither with 'user1' nor as sudo/root].
[If it makes any difference, I am running ubuntu]
-
Ali Hashemi over 10 yearsCan you change the owner using
chown username file
? -
Dhara over 10 years@Pazis No, I don't have permissions for that! It's a recursive problem :(
-
vishram0709 over 10 years@MariusMatutiae - In your computer you will be the owner of the files so you won't find any problem in your system.
-
MariusMatutiae over 10 yearsRight. Are you telling me you are trying to erase someone else's files?
-
vishram0709 over 10 years@Dhara - What do you mean by its a recursive problem? Are these files created by you or someone else?
-
Unknowntiou over 10 yearsMaybe your file is immutable? See man chattr, read about immutable (i) attribute.
-
chrismacp over 8 yearsDid you ever sort this issue as I have the same problem. A program created a bunch of files for me that have no write permission for any user. I cant use chmod/chown/rm with sudo so am stuck.
-