Ubuntu – Deleting an Undeletable File
Here’s the story on why I had an undeletable file and how I finally deleted it:
I wrote a short Python script that had matplotlib as a library. I go to run the script and:
chiefinnovator@MAIN1:~$ python /home/chiefinnovator/stock_market_prediction/create_data_file.py
Traceback (most recent call last):
File "/home/chiefinnovator/stock_market_prediction/create_data_file.py", line10, in ?
from matplotlib.finance import quotes_historical_yahoo
File "/usr/lib/python2.4/site-packages/matplotlib/__init__.py", line 733, in ? rcParams = rc_params()
File "/usr/lib/python2.4/site-packages/matplotlib/__init__.py", line 689, in rc_params
for line in file(fname):
IOError: [Errno 13] Permission denied: '/etc/matplotlibrc'
Hmm, I don’t know what this file is or why I was denied from it but let’s go ahead and fix that:
chiefinnovator@MAIN1:~$ sudo chown -v chiefinnovator "/etc/matplotlibrc"
Password:
chown: changing ownership of `/etc/matplotlibrc': Operation not permitted
failed to change ownership of `/etc/matplotlibrc' to chiefinnovator
That’s certainly odd. I browse over to the file in Nautilus by running:
gksudo nautilus
and I see that it’s a 0 byte file owned by root (allegedly) and has no permissions.
So I figure I’ll go ahead and delete it:
chiefinnovator@MAIN1:~$ sudo rm -v /etc/matplotlibrc
rm: remove write-protected weird file `/etc/matplotlibrc'? y
rm: cannot remove `/etc/matplotlibrc': Operation not permitted
And same message with “sudo rm -f /etc/matplotlibrc”.
Ok, this is all very strange, and rm called my file “weird”! Time to start searching. This link provides these two ideas:
chiefinnovator@MAIN1:~$ fuser -u /etc/matplotlibrc
chiefinnovator@MAIN1:~$ fuser -ku /etc/matplotlibrc
and this idea:
chiefinnovator@MAIN1:~$ sudo debugfs debugfs 1.38 (30-Jun-2005)
debugfs: open -w /dev/hda3
debugfs: rm /etc/matplotlibrc
rm: File not found by ext2_lookup while trying to resolve filename
debugfs: q
Still nothing works. Finally as a last resort I try restarting the computer. I come back into a terminal try the simple:
chiefinnovator@MAIN1:~$ sudo rm -fv /etc/matplotlibrc
Password:
chiefinnovator@MAIN1:~$
And it works!
so I go ahead and recreate the file so that some other thing hopefully doesn’t try to create it again in an un-deleteable way.
chiefinnovator@MAIN1:~$ sudo touch /etc/matplotlibrc
And now everything works! The moral of the story is to try restarting your computer first! Disclaimer: I have no idea what I’m doing, following these steps may harm you in some way.
Finally my search terms:
- “chown: changing ownership of *: Operation not permitted”
- chown: changing ownership of `/etc/matplotlibrc’: Operation not
- the owner could not be changed
- “the owner could not be changed”
- sudo + “operation not permitted”
- sudo “operation not permitted” site:http://www.ubuntuforums.org/
[tags]ubuntu,sudo,rm,sudo rm,delete,chown,matplotlibrc,matplotlib,ownership,touch,debugfs,fuser,gksudo,nautilis,nautilus[/tags]
Maybe some minor filesystem corruption there, judging by what debugfs said? Probably should have tried an fsck right then.
Good tip, Anonymous. I’ll try an fsck tonight. Though it may be too late to get any insight into this problem.
I am having the same problem now, can’t delete an empty directory. When listing the parent directory, the directory that I can’t delete is in green background, which I assume indicating that something is wrong with that file.
Anyway, I tried reboot, didn’t work. And i could not use debugfs as it gives me a permission error as well.
I think no root account is really bad. I actually tried to enable the root account using the ideas found on Google but didn’t work.
Hi, Alan,
Sorry to hear about your troubles. I figured my problem was an isolated incident but it appears to not be the case. I’d hit up the Ubutnu forums and see if someone can get you an answer.