删除文件名中含有奇数字符的文件
我无法删除作为备份的备份副本的文件...我不记得它所经过的所有文件系统字符集。
不管怎样,今天的文件是这样的:
nas# ls -al
ls: cannot access Sécurité: No such file or directory
total 32
drwx------ 4 sambacam sambacam 20480 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#
我什至尝试用 Python 编写代码,但没有成功:
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'
>>>
有什么想法吗?
我已经运行 fsck 来检查不一致的情况。
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 20480 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您遇到了更严重的问题:
这意味着
ls(1)
无法找到权限、链接计数、所有者文件的 、组、大小或mtime。它只有一个文件名。如果目录结构指向一个文件,但该文件的索引节点丢失了,则可能会发生这种情况。我希望 fsck 能够找到它并清理目录条目,但如果没有发生,您可能无法清空该文件系统上的该目录。 (您可以将其移动到任何您想要的位置,甚至可以移动到
/lost+found
中,并且不会再被它打扰......)也许
debugfs(8)
工具会对学习更多有用吗?I think you've got worse problems:
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?您尝试过 inode 编号技巧吗?执行:
该列表中的第一个数字是索引节点号。
-b
开关使ls
不会尝试打印不可打印的字符。一旦你从文件中获得了索引节点号,请尝试:(顺便说一句:这是 UTF-8 编码。)但
我不确定它是否有效。
ls
找不到文件的元数据(时间戳和权限位)这一事实看起来像是文件系统损坏。Have you tried with the inode number trick? Do:
The first number in that list is the inode number. The
-b
switch makesls
not try to print non-printable chars. Once you have the inode number from the file, try:(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.