2011-06-05 45 views
2

我無法刪除備份副本的文件...我不記得它已經通過的所有文件系統字符集。刪除文件中帶有奇數字符的文件

不管怎麼說,今天這裏的文件:

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檢查不一致性。

+0

FS類型是ext2! – CamilleHuot 2011-06-05 09:02:46

+0

你的語言環境是什麼?嘗試使用UTF-8(這是保持健全的唯一方法)。 – 2011-06-05 09:08:49

+0

我的語言環境是POSIX,UTF8沒有安裝在我的電腦上。也許你是對的,文件名問題可以修復。 – CamilleHuot 2011-06-05 17:20:57

回答

5

我覺得你有更嚴重的問題:

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

這意味着ls(1)無法找到權限鏈接數所有者大小,或mtime你的檔案。它只有一個文件名。

如果目錄結構指向一個文件,但該文件的inode已丟失,則可能發生這種情況。我希望fsck能找到它並清理目錄條目,但如果沒有發生,你可能無法在這個文件系統上清空這個目錄。 (你可以將它移動到任何你想要的位置,即使是進入/lost+found,也不會再被它困擾......)

也許debugfs(8)工具對學習更多內容有用嗎?

+0

目前,我選擇了你的精彩解決方案將目錄移至lost + found目錄。你知道我如何使用debugfs來查看/修復這個問題嗎? – CamilleHuot 2011-06-05 17:15:30

+0

@Camille,我不願意提出任何建議,只是因爲它可能會讓你的fs腐敗變得更糟。請備份。 :)也就是說,它看起來像你可以使用'cd'命令導航到正確的目錄。接下來會發生一些賭博:如果你使用'rm',它會在取消鏈接目錄項後嘗試取消分配inode。看起來很危險。如果使用'unlink',它將簡單地取消目錄條目的鏈接,並單獨保留inode。 (這可能是更安全的選擇。)但是,我再也不能強調備份的重要性。 :) – sarnold 2011-06-06 05:23:07

3

您是否嘗試過使用inode號碼技巧?請執行以下操作:

ls -ilb 

該列表中的第一個數字是inode編號。 -b開關使ls不會嘗試打印不可打印的字符。一旦你從文件的inode編號,請嘗試:

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

(BTW:這是UTF-8編碼。)

我不知道它會工作,雖然。 ls未找到文件的元數據(時間戳和權限位)看起來像是文件系統損壞。

+1

優秀的把戲:) – sarnold 2011-06-05 09:13:12

+0

我不明白這是如何幫助。 'NAS#LS -ibl LS:不能Access中使用S \ 303 \ 251curit \ 303 \ 251:沒有這樣的文件或目錄 總0 36626459 d ????????? ? ? ? ? ? S \ 303 \ 251curit \ 303 \ 251 nas#find。 -inum 36626459 -exec rm -i {} \; 找到:'。/ S \ 303 \ 251curit \ 303 \ 251':沒有這樣的文件或目錄 nas#' – CamilleHuot 2011-06-05 17:18:25

+1

那麼在這種情況下,它似乎並不是因爲你的FS似乎已經損壞。在某些情況下,它確實有所幫助,在這些情況下,您無法通過更傳統的方式獲取文件名。 – Mat 2011-06-05 17:21:03