在linux中,有時候會遇到檔名是亂碼或者是某些特殊中文的檔案,這時候通過檔名就很難刪除。
同時,對於linux中的任何一個檔案都必然有其唯一的inode值,這時候就可以通過inode來刪除異常檔名的檔案
操作的物件一般為類似下面的檔案:
[[email protected] tmp]# ll總用量
61404
-rw-r--r-- 1 root root 0 6月 16
14:58 ?
-rw-r--r-- 1 root root 0 6月 19
12:29 ??
-rw-r--r-- 1 root root 0 6月 21
14:53 ???3kqu
-rw-r--r-- 1 root root 0 6月 21
14:53 ?6;?xf??ma???9???t֙
-rw-r--r-- 1 root root 0 6月 19
12:29 [email protected]][email protected]?xlai]?k
產生這類檔案的原因:
1.上傳檔案時網路異常導致
2.windows建立的某些檔名在linux下無法正常識別
3.中文特殊字元無法識別
解決方法如下:
1.查詢這些檔案的inode值
ll -i
[[email protected] tmp]# ll -i總用量
61404
15206100 -rw-r--r-- 1 root root 0 6月 16
14:58 ?
15206090 -rw-r--r-- 1 root root 0 6月 19
12:29 ??
15206092 -rw-r--r-- 1 root root 0 6月 21
14:53 ???3kqu
15206233 -rw-r--r-- 1 root root 0 6月 21
14:53 ?6;?xf??ma???9???t֙
15206235 -rw-r--r-- 1 root root 0 6月 21
14:53 a??k?
以上,最左邊的數字即為對應檔案的inode值,不過無法直接使用rm命令刪除檔案,需要其他命令配合使用
2.刪除異常檔案
正常情況下這些檔案也是可遇不可求的,不過涉及到rm的命令要小心謹慎,事前做一下測試,熟練下操作怎麼也是不為過的,沒有這些亂碼的檔案,可以使用正常的檔案做測試,
有以下這幾種方法:
先建立需要的檔案
[[email protected] tmp]# cd /tmp[[email protected] tmp]#
touch
aaa bbb ccc ddd eee
[[email protected] tmp]# ll -i
總用量
01442581 -rw-r--r-- 1 root root 0 9月 22
15:00
aaa1442582 -rw-r--r-- 1 root root 0 9月 22
15:00
bbb1442583 -rw-r--r-- 1 root root 0 9月 22
15:00
ccc1442584 -rw-r--r-- 1 root root 0 9月 22
15:00
ddd1442585 -rw-r--r-- 1 root root 0 9月 22
15:12 eee
(1)使用find自帶的delete引數進行刪除aaa檔案
[[email protected] tmp]# find ./*-inum 1442581 -delete
[[email protected] tmp]# ll -i
總用量 0
1442582 -rw-r--r-- 1 root root 0 9月 22 15:00 bbb
1442583 -rw-r--r-- 1 root root 0 9月 22 15:00 ccc
1442584 -rw-r--r-- 1 root root 0 9月 22 15:00 ddd
1442585 -rw-r--r-- 1 root root 0 9月 22 15:12 eee
(2)使用find自帶的-exec引數結合rm命令刪除bbb檔案(進行刪除確認)
[[email protected] tmp]# find ./*-inum 1442582 -exec rm -i {} \;
rm:是否刪除普通空檔案 "./bbb"?y
[[email protected] tmp]# ll -i
總用量 0
1442583 -rw-r--r-- 1 root root 0 9月 22 15:00 ccc
1442584 -rw-r--r-- 1 root root 0 9月 22 15:00 ddd
1442585 -rw-r--r-- 1 root root 0 9月 22 15:12 eee
(3)使用find自帶的-exec引數結合rm命令刪除ccc檔案(不進行刪除確認)
[[email protected] tmp]# find ./*-inum 1442583 -exec rm -f {} \;
[[email protected] tmp]# ll -i
總用量 0
1442584 -rw-r--r-- 1 root root 0 9月 22 15:00 ddd
1442585 -rw-r--r-- 1 root root 0 9月 22 15:12 eee
(4)使用find和xargs結合刪除ddd檔案(無法使用-i引數進行刪除確認)
[[email protected] tmp]# find ./*-inum 1442584 |xargs rm -f
[[email protected] tmp]# ll -i
總用量 0
1442585 -rw-r--r-- 1 root root 0 9月 22 15:12 eee
(5)使用rm命令刪除指定檔案(由find命令找到的檔名)
[[email protected] tmp]# rm `find ./*-inum 1442574`
rm:是否刪除普通空檔案 "./eee"?y
[[email protected] tmp]# ll
總用量 0
# 使用find命令的-inum選項確認檔名
[[email protected] tmp]# touchfff[[email protected] tmp]# ll -i
總用量
01442574 -rw-r--r-- 1 root root 0 9月 22
15:38
fff[[email protected] tmp]#
find ./*
-inum 1442574
./fff
總結一下:
以上幾種不同的刪除方式,總體來說都是通過指定檔案的inode值,使用find命令的-inum選項確認其檔名,然後傳遞給rm命令進行刪除
完畢,呵呵呵
linux下的文件處理及tar命令
1 使用cat命令進行縱向合併 使用 是將左邊的內容覆蓋到右邊 使用 是將左邊的內容追加到右邊文件中 還可使用 將不同檔案進行合併 2 管道符 統計行數 使用wc l直接計算行數 管道符計算單個檔案的行數 計算多個檔案合併後的行數 3 tar命令打包檔案 注意引數不帶 比如cvf,不能是 cvf c...
linux 下使用man 無法檢視庫函式的文件
遇到的問題 想用man 檢視c標準庫函式的man pages,輸入命令 man 2 read bash命令列報錯了 第2節沒有關於read的手冊頁條目在網上查瞭解決方案,這裡也記錄下關於man 的用法 man 中對命令和函式進行了分類,我們在查詢時如果沒有指定頁面,查到的結果可能並不是我們想要的,底...