开发者

Delete file with odd character in filename

I cannot delete a file that is copy of a backup of a backup... I don't remember all the filesystem character set it has passed by.

Anyway, today here's the file:

nas# ls -al
ls: cannot access Sécurité: No such file or directory
total 32
drwx------ 4 sambacam sambacam 2开发者_如何学Python0480 Jun  5 01:38 .
drwxr-xr-x 3 sambacam sambacam 12288 Jun  5 01:38 ..
d????????? ? ?        ?            ?            ? S??curit??
nas# cd S*
cd: 13: can't cd to Sécurité
nas# rm "Sécurité"
rm: cannot remove `S\303\251curit\303\251': No such file or directory
nas# rm S*
rm: cannot remove `S\303\251curit\303\251': No such file or directory
nas# 

I even tried to code in Python without success:

nas# python
Python 2.5.2 (r252:60911, Jan 24 2010, 20:48:41) 
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> d=os.listdir('.')
>>> d
['S\xc3\xa9curit\xc3\xa9']
>>> d[0]
'S\xc3\xa9curit\xc3\xa9'
>>> os.remove(d[0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 2] No such file or directory: 'S\xc3\xa9curit\xc3\xa9'
>>> 

Any idea?

I already ran fsck to check for inconsistencies.


I think you've got worse problems:

d????????? ? ?        ?            ?            ? S??curit??

This means that ls(1) was unable to find permissions, link count, owner, group, size, or mtime of your file. All it has is a filename.

This could happen if the directory structure points to a file, but the inode for that file has gone missing. I would hope a fsck would find it and clean up the directory entry, but if that hasn't happened, you might not be able to ever empty this directory on this filesystem. (You could move it wherever you wanted, even into the /lost+found, and not be bothered by it again...)

Perhaps the debugfs(8) tool would be useful in learning more?


Have you tried with the inode number trick? Do:

ls -ilb

The first number in that list is the inode number. The -b switch makes ls not try to print non-printable chars. Once you have the inode number from the file, try:

find . -inum the_number_from_above -exec rm -i {} \;

(BTW: that's UTF-8 encoding.)

I'm not sure it will work though. The fact that ls isn't finding the file's metadata (timetamps and permission bits) looks like filesystem corruption.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜