
差異的解釋是什麼:
$ ls -l /Applications/Safari.app/Contents/Info.plist
-rw-r--r-- 1 root wheel 15730 11 jui 15:02 /Applications/Safari.app/Contents/Info.plist
$ du -sh /Applications/Safari.app/Contents/Info.plist
0B /Applications/Safari.app/Contents/Info.plist
一旦文件被複製到我的主資料夾中,ls
並du
報告相同的號碼。
$ cp /Applications/Safari.app/Contents/Info.plist .
$ du -sh Info.plist; ls -l Info.plist
16K Info.plist
-rw-r--r-- 1 ant staff 15730 17 oct 16:53 Info.plist
兩個目錄都位於該分割區 ( / )
diskutil info /
Device Identifier: disk0s2
Device Node: /dev/disk0s2
Part of Whole: disk0
Device / Media Name: ml2013
Volume Name: OSX.10.8
Escaped with Unicode: OSX.10.8
Mounted: Yes
Mount Point: /
Escaped with Unicode: /
File System Personality: Journaled HFS+
Type (Bundle): hfs
Name (User Visible): Mac OS Extended (Journaled)
Journal: Journal size 40960 KB at offset 0xc83000
Owners: Enabled
這是 stat 的輸出:
$ stat Info.plist
16777218 8780020 -rw-r--r-- 1 root wheel 0 15730 "Oct 17 17:47:12 2013" \
"Jun 11 15:02:17 2013" "Jun 11 15:02:17 2013" "Apr 27 11:49:34 2013"\
4096 0 0x20 Info.plist
答案1
我可能發現了一些東西:
OS X 上的 ls 指令有這個開關:
-O Include the file flags in a long (-l) output.
結果是:
$ ls -O Info.plist
-rw-r--r-- 1 root wheel compressed 15730 11 jui 15:02 Info.plist
我剛剛檢查(實驗性)總是du
報告0
HFS+ 壓縮檔。
複製壓縮檔案並解壓縮它們; so 邏輯上du
報告複製的未壓縮檔案上的正確檔案。
這是一個解釋對於以下行為du
:
HFS+ 檔案壓縮
在 Mac OS X 10.6 中,Apple 在 HFS+ 中引入了檔案壓縮。壓縮最常用於作為 Mac OS X 一部分安裝的檔案;使用者檔案通常不被壓縮(但當然可以!)。就 Apple 的檔案系統 API 而言,讀取和寫入壓縮檔案是透明的。
壓縮檔案有一個空的資料叉。這意味著不支援 HFS+ 檔案壓縮(包括 4.0.0 之前的 TSK)的取證工具將看不到與壓縮檔案關聯的任何資料!
Mac OS X and iOS Internals: To the Apple's Core
Jonathan Levin 在第 16 章:To B(-Tree) or not to be - HFS+ 檔案系統中 也對此主題進行了討論。
也AFSC工具可以幫助查看資料夾中壓縮了哪些檔案。
$ afsctool -v /Applications/Safari.app/
/Applications/Safari.app/.:
Number of HFS+ compressed files: 1538
Total number of files: 2247
Total number of folders: 144
Total number of items (number of files + number of folders): 2391
Folder size (uncompressed; reported size by Mac OS 10.6+ Finder): 29950329 bytes / 34.7 MB (megabytes) / 33.1 MiB (mebibytes)
Folder size (compressed - decmpfs xattr; reported size by Mac OS 10.0-10.5 Finder): 21287197 bytes / 23.8 MB (megabytes) / 22.7 MiB (mebibytes)
Folder size (compressed): 22694835 bytes / 25.2 MB (megabytes) / 24 MiB (mebibytes)
Compression savings: 24.2%
Approximate total folder size (files + file overhead + folder overhead): 26353338 bytes / 26.4 MB (megabytes) / 25.1 MiB (mebibytes)
答案2
使用時du
,您要比較針對檔案系統的 2 次不同運行的結果,您需要確保使用 switch --apparent-size
。
例子
這是 CIFS 安裝的共用。
$ du -sh somedir
50M somedir
$ du -sh --apparent-size somedir
45M somedir
摘自 du 手冊頁
--apparent-size
print apparent sizes, rather than disk usage; although the apparent
size is usually smaller, it may be larger due to holes in (‘sparse’)
files, internal fragmentation, indirect blocks, and the like
那麼這是什麼一回事呢?
這讓很多人感到困惑,但請記住,當檔案儲存到磁碟時,它們會消耗空間區塊,即使它們只使用這些區塊的一部分。當您在du
沒有使用的情況下運行時,--apparent-size
您將根據所使用的磁碟區塊空間量獲得大小,而不是檔案消耗的實際空間。
0B尺寸怎麼樣?
0B /Applications/Safari.app/Contents/Info.plist
這很可能是一個連結。執行此命令將顯示是否是這種情況。
$ ls -l /Applications/Safari.app/Contents | grep Info.plist
答案3
我的答案與其他人一致,但我還不能發表評論,所以我要開始新的:
/Applications 中的大多數檔案都經過壓縮,當您複製它時,這些檔案就會遺失。當在 HFS+ 中使用壓縮時,檔案資料會儲存在資源叉中或者如果它足夠小(小於 4k),則為擴展屬性。如果它在資源分叉中,du(至少在 Yosemite 上)將顯示它的實際磁碟使用情況(以區塊為單位)。如果它完全在屬性中,它將顯示 0。