删除文件名中含有奇数字符的文件

发布于 2024-11-12 17:09:56 字数 1152 浏览 4 评论 0原文

我无法删除作为备份的备份副本的文件...我不记得它所经过的所有文件系统字符集。

不管怎样,今天的文件是这样的:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清君侧 2024-11-19 17:09:56

我认为您遇到了更严重的问题:

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

这意味着 ls(1) 无法找到权限链接计数所有者文件的 大小mtime。它只有一个文件名。

如果目录结构指向一个文件,但该文件的索引节点丢失了,则可能会发生这种情况。我希望 fsck 能够找到它并清理目录条目,但如果没有发生,您可能无法清空该文件系统上的该目录。 (您可以将其移动到任何您想要的位置,甚至可以移动到 /lost+found 中,并且不会再被它打扰......)

也许 debugfs(8) 工具会对学习更多有用吗?

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?

段念尘 2024-11-19 17:09:56

您尝试过 inode 编号技巧吗?执行:

ls -ilb

该列表中的第一个数字是索引节点号。 -b 开关使 ls 不会尝试打印不可打印的字符。一旦你从文件中获得了索引节点号,请尝试:(

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

顺便说一句:这是 UTF-8 编码。)但

我不确定它是否有效。 ls 找不到文件的元数据(时间戳和权限位)这一事实看起来像是文件系统损坏。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文