ls和du顯示資料夾的size

本人學linux沒多久發現一件事情,使用lsdu顯示資料夾的size竟然不一樣,找了一些資料才懂,所以才決定發這篇文,剛學linux的人可以看一下,已經懂得高手就麻煩你們看一下,有錯請糾正。

基礎知識

ls - list the directory content

ls [OPTION] [FILE]

list information about FILEs
- -a list all entry
- -h print size for human readable format
- -l use long list format

du - estimate file space usage

du [OPTION] [FILE]

summarise disk usage of each FILE, recursively for directories.
- -s display only a total for each argument
- -h print size for human readable format

進入主題

我在code資料夾,發現只有306B(第一欄.),可是底下隨便加起來都超過


$ls -ahl
total 272
drwxr-xr-x@  9 kai  staff   306B 16 Nov 15:16 .
drwx------+ 19 kai  staff   646B 21 Nov 16:32 ..
-rw-r--r--@  1 kai  staff    14K 21 Nov 16:57 .DS_Store
drwxr-xr-x@  8 kai  staff   272B 25 Sep 20:09 .metadata
drwxr-xr-x@  5 kai  staff   170B 25 Sep 20:09 .recommenders
drwxr-xr-x@  7 kai  staff   238B 29 Oct 17:25 C Project
drwxr-xr-x@ 12 kai  staff   408B 25 Oct 01:18 Eclipse Project
-rw-r--r--@  1 kai  staff     0B  6 Sep 01:57 Icon?
drwxr-xr-x@ 11 kai  staff   374B  1 Oct 15:41 Xcode Project

用用看du,這好像纔是我們想要的

$du -sh
188M    .

看到了這篇才發現問題所在,ls列出的是inode的大小,並不是在目錄裡所有資料的大小.

reference

linux show size of folder contents in ls or some other command
using ls to show directory size
The du command

發佈了25 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章