Get the App
SLTechnology News&Howtos  ›  Servers  › 

What are the reasons for the different disk occupancy between du-sh and ls-lh under Linux

Shulou Source: shulou.com Published: 2022-06-01 04:59:07 10月04日 Update

This article will explain in detail the reasons for the difference between du-sh and ls-lh display disks under Linux. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Reason

Du-sh * calculates how much space the file takes up on disk and how many block it takes.

Ls-lh calculates the actual size of the file.

Generally speaking, block is rarely filled up when storing files, so du-sh * is generally larger than ls-lh.

But there are also some special files, such as sparse file.

Sparse files (Sparse File)

Sparse files, which is a feature of file systems such as the UNIX class. Sparse files are basically the same as other ordinary files, except that some of the data in the file is all zero, and this part of the data does not take up disk space.

It can delay disk space allocation and is especially suitable for virtual machines. For example, if a 100G file is allocated as a disk, 100G of space is identified in the virtual machine, but the actual physical machine is only allocated to the space already used.

On the "Linux du-sh and ls-lh display disk occupancy is not the same reason" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: File disk space reason sparse article allocation actual data more storage good practical ordinary special same generally speaking content just size Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi macOS Microsoft Xiaomi OPPO Reno