Unix:关于一个file在file system和disk中占用空间

參考文献:

Harley Hahns:Guide to Unix and Linux。 Chap 24


——》首先要有的关键概念:the amount of "disk space" used by a file is not the same as the amount of data in the file.


——》其次,理解在file system和disk(or other storage medium)中都存在各自的最小空间单元:file system中叫“block”;disk中叫“allocation unit”。

   这两个最小空间单元关系:The size of "allocation unit" depends on the filesystem and the storage device。

比方參考文献作者计算机中,filesystem的最小占用单元block为1K Bytes,而disk allocation units 为8K Bytes。所以,有一个文件含有1B的data,则在filesystem中占用1个block(1K),在disk中占用8K的disk space


******************************************************************************

于是以下的问题:怎样detemine size of block? 怎样determine size of allocation unit?

——size of allocation units:

*先创建一个非常小的文件

*再用ls -l file查看这个文件含有的实际data有多少(Byte为单位)。显示在时间前面

*再用du -h file查看how much "disk space" the file takes up

这查出来的disk space就是你的disk中最小占用单元的大小。我的计算机上查出是4K


——size of block in filesystem:

思路是通过在管理员权限下用dumpe2fs命令查看在filesystem中存在的一个block:SUPERBLOCK的性质。查看它的Block size来确定在filesystem中一个block有多大

*先用df命令来find out the name of the special file that represents the filesystem, 如/dev/hda1

*再用su取得superuser的权限

*在superuser的权限在使用dumpe2fs,并用grep命令搜集“Block size”信息:dumpe2fs /dev/hda1 | grep "Block size"

这查出来的Block size就是在你的file system中一个block的最小占用空间,我的计算机上查出是1024

原文地址:https://www.cnblogs.com/zsychanpin/p/7365177.html