1. 程式人生 > 實用技巧 >ll 檔案比磁碟空間大? linux

ll 檔案比磁碟空間大? linux

處理運維問題的時候發現,檔案比磁碟空間大

  1. 用 ll 檢視檔案的時候發現檔案有400G,而檔案系統只有200G,感覺很奇怪,就去做了個實驗
[root@lin ~]# nohup dd if=/dev/zero of=test bs=1M count=100000 &
[1] 3497
[root@lin ~]# nohup: ignoring input and appending output to ‘nohup.out’
^C
[root@lin ~]# ll test 
-rw-r--r-- 1 root root 3767242752 Sep 12 18:30 test
[root@lin ~]# du -sh test 
12G	test
[root@lin ~]# > test 
[root@lin ~]# du -sh test 
1.8G	test
[root@lin ~]# ll test 
-rw-r--r-- 1 root root 18232692736 Sep 12 18:31 test
[root@lin ~]# kill 3497
  1. 日誌清理大小,一般為了不終止服務,會選擇使用 > 的方式去填空檔案,邏輯大小沒有改變,所有會造成這個假象
test
原始:
0101010100101010
> 後 :
/      空洞     /0101010100101010
# 後面追加的內容會寫到置空前的後面
  1. 結論:
    ll: 看的是檔案的邏輯大小
    du:看的是檔案在磁碟上實際所佔的block數
    實際是看 du 的值