Multiple . and .. in a folder
Here's the situation. I have a program running on Fedora 8 which creates a folder and saves some files in it. After a certain amount of time it will then delete this folder using the command:
rm -rf [folder name] There's no problem with the logic of the program and it works well 99% of the time. However, I recently encountered a problem where the deleting of the folder encountered this error message: rm: cannot remove directory `[folder name]': Directory not empty Looking in the folder with ls shows that the folder is empty. Using the command ls -fl shows me this: drwxr--r-- 2 root root 135168 2009-04-15 02:13 . drwxrwxrwt 13 root root 4096 2009-04-15 01:51 .. drwxr--r-- 2 root root 135168 2009-04-15 02:13 . drwxrwxrwt 13 root root 4096 2009-04-15 01:51 .. I'm thinking that I'm getting an error deleting this folder because of the duplicate . and .. So now I'm wondering how this could have happened and how I can delete the folder. I've tried following the different ways to delete the folder in the link below but still can't. http://www.labtestproject.com/linuxcmd/rm.html Any help would be appreciated. |
Look at "ls -li" and see if the inodes are different.
I wonder if there is a file that has an illegal filename of ".." or if those aren't actually periods but a character with a similar typographical appearance. However, rm -rf <dirname> should delete the files before the directory. Try the unlink command instead. If the inode of one of the ".." filenames is different than the inode of the parent directory, you could use the find command: find . -inum <inode#> option and -exec rm '{}' to try to delete it. Be careful you don't delete the parent directory by mistake. Code:
ls -ldi testdir Also always be careful when deleting hidden files. Don't use "rm .*". That will also match ".." which is the parent directory. I use "rm .[^.]*" instead. |
With ls -lia I get
181934543 drwxr--r-- 2 root root 135168 2009-04-15 02:13 . 181934543 drwxr--r-- 2 root root 135168 2009-04-15 02:13 . 28639233 drwxrwxrwt 13 root root 4096 2009-04-15 01:51 .. 28639233 drwxrwxrwt 13 root root 4096 2009-04-15 01:51 .. So the inodes are the same. I already tried deleting with the inode but could not. I also tried unlinking the folder itself as well as the .. but I just get the error message that I can't do that because it is a directory. I thought about this being a corrupt file system but I haven't seen any signs of problems in dmesg or the messages logs. I will probably have to add error checking on something like this but I was really hoping to just find out how this could have happened in the first place. |
Your script seems to run as root. I don't know the purpose of your script, but you should avoid automated tasks with root permissions, unless it's unavoidable.
Having directory contents with the same name, especially if it's . and .. seems rather like filesystem corruption. Even more as 'rm -rf' is supposed to delete directories unregarded their contents. You should run fschk to sort it out. |
Well, checking back on the server, it seems that it's having a problem deleting another folder. Different set of problems this time. Just trying to ls the files in the directory is returning an error.
In conclusion, it seems like what was suggested is true, that the file system might be corrupt. Thanks for the replies. |
All times are GMT -5. The time now is 10:51 PM. |