Article Title: Calculation of file space occupation. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
First, we need to first understand the size of the I/o block (a cluster in Chinese) of your file system. The size of the I/O BLOCK in this file system is 4096 Bytes.
It is the smallest read/write and allocation unit of the file system. You cannot be smaller than this size for each read/write operation. Even if your file has only one byte. In addition, the storage of files on the hard disk is also in this unit. That is to say, if the file size is smaller than this value, the space occupied by the file on the disk is 4096 bytes.
The specific algorithm for space occupation is: (1 (file size/4096) × 4096. Based on this, you can calculate the space usage of the files in the example you listed: for example, the file length of file.txt is 34890 (ls-l), 34890 divided by 4096, which is about 8.5, the first method is 9, that is, the file occupies 9 blocks on the disk, and each BLOCk is 4 K. Therefore, the space occupied by these two files is 36 K.
This rule is also suitable for directories, but there will be no directories with 0, even empty directories.