You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux中ls -l命令的total计数含义及显示原因解析

Understanding the total Line in ls -l

Hey there! Let's clear up your questions about that mysterious total line you see when running ls -l on Linux—it's actually more useful than it might seem at first glance.

What does total represent?

The total number is the total number of 1KB-sized disk blocks used by all the files (and directories) listed in the output. Let's break that down further:

  • Linux filesystems allocate storage in fixed-size "blocks" (the exact size depends on your filesystem, like 4KB for ext4 by default). Even a tiny 1-byte file will take up at least one full block of space, since you can't allocate a fraction of a block.
  • GNU ls (the default on most Linux distros) calculates total by converting the actual filesystem block usage into 1KB units. So if a file uses one 4KB block, that counts as 4 in the total number.

For example, if you have two 1-byte files, each taking up a 4KB block:

$ ls -l
total 8
-rw-r--r-- 1 alice alice 1 Aug 10 14:30 tiny-file-1
-rw-r--r-- 1 alice alice 1 Aug 10 14:30 tiny-file-2

Here, each file uses 4 x 1KB blocks, so 4 + 4 = 8, which is the total value shown.

Why does ls -l show this total line?

It's a quick way to see the actual disk space consumed by the listed files, not just the sum of their logical sizes.

  • If you just added up the byte sizes of the files (1 + 1 = 2 bytes), that wouldn't tell you how much space they're really taking up on your drive. The total line fixes that by showing you the real storage footprint.
  • It's especially helpful when you have lots of small files—you can immediately see how much disk space they're collectively using, instead of doing the math yourself.

Note: If you use ls -la to include hidden files, the total number will include the disk blocks used by those hidden files too. You can also adjust the block size used for calculating total with the --block-size flag, like ls -l --block-size=4K to show total in 4KB units.

内容的提问来源于stack exchange,提问作者Shivani Hajare

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:35:47