鍍金池/ 問答/人工智能  Linux  HTML/ linux: ls -l中的文件大小比du得到的大是怎么回事?

linux: ls -l中的文件大小比du得到的大是怎么回事?

查看kafka某topc下的文件

[root@localhost TOPIC_QUEUE_ID-0]# ls -l
total 2932
-rw-r--r-- 1 root root 10485760 Oct 30 2017 00000000000003771019.index
-rw-r--r-- 1 root root 2985451 Oct 30 2017 00000000000003771019.log
-rw-r--r-- 1 root root 10485756 Oct 26 2017 00000000000003771019.timeindex
[root@localhost TOPIC_QUEUE_ID-0]# du -m 00000000000003771019.log
3 00000000000003771019.log
[root@localhost TOPIC_QUEUE_ID-0]# du -m 00000000000003771019.index
1 00000000000003771019.index
[root@localhost TOPIC_QUEUE_ID-0]# du -k 00000000000003771019.index
8 00000000000003771019.index
[root@localhost TOPIC_QUEUE_ID-0]# du -k 00000000000003771019.log
2920 00000000000003771019.log

index文件在ls -l下是10M,在du -k下才8KB
怎么回事?

回答
編輯回答
呆萌傻

因?yàn)槟憧吹降氖?a rel="nofollow noreferrer">稀疏文件

比如虛擬機(jī)的硬盤文件,就是一種典型的稀疏文件。而kafka的官方文檔也說了,日志文件就是創(chuàng)建一個(gè)稀疏文件,比如下面的內(nèi)容就摘自于官方文檔:

PROPERTY DEFAULT DESCRIPTION
log.index.size.max.bytes 10 * 1024 * 1024 The maximum size in bytes we allow for the offset index for each log segment. Note that we will always pre-allocate a sparse file with this much space and shrink it down when the log rolls. If the index fills up we will roll a new log segment even if we haven't reached the log.segment.bytes limit.

注意官方文檔的描述,每個(gè)log segment就是預(yù)先創(chuàng)建的稀疏文件

2018年1月1日 04:04