27

I have an empty directory. I am using following command to view the contents of that directory.

ls -lart

The output I get is below.

total 12
drwxr-xr-x 5 root  root  4096 Oct  2 12:26 ..
drwxr-xr-x 2 apx   aim   4096 Nov 29 18:40 .

I don't have any files in this directory, then what counts out to 12 here (total 12)?

Kusalananda
  • 333,661
g4ur4v
  • 1,764
  • 8
  • 29
  • 34

3 Answers3

22

That is the total number of blocks taken up by the files, although I would expect the total to be 8 instead of 12 (using 1k blocks). Try ls -as1 to see the size in blocks of each file.

doneal24
  • 5,059
  • This is the output I get... total 12 4 drwxr-xr-x 5 root root 4096 Oct 2 12:26 .. 8 drwxr-xr-x 2 apx aim 4096 Nov 29 18:40 . – g4ur4v Nov 29 '12 at 14:00
7

The "total" is the disk usage of listed files (because of -a including the . and .. entries) in blocks (1024 bytes or if POSIXLY_CORRECT is set in 512 bytes), not including the content of subdirectories.

If same files are not referenced and therefore listed twice (hard-links), you can get the same output with

du -Ss

or in human readable units

du -Ssh
jofel
  • 26,758
  • 3
    No, ls just adds up the disk usage of the files listed (so . and .. are included only if -a is included), and contrary to du, ls doesn't account for hardlinks, so the result will be different. -a, -A (GNU), -L at least will affect the value reported. Also note that with GNU ls, the value will be different if POSIXLY_CORRECT is in the environment (block size 512) or not (block size 1024) – Stéphane Chazelas Nov 29 '12 at 13:54
  • 1
    Thanks Stephane Chazelas for your comment. I improved my answer. As GNU's du react also on POSIXLY_CORRECT, it should use the same block size. – jofel Nov 29 '12 at 14:27
2

total count of blocks, it includes also indirect blocks.

b3h3m0th
  • 352