2

Can someone explain how this calculation is done for disk usage? I am confused because in line1 4k , line2 4k line3 36k and total is also 36k

 $ du -ch
 4.0K   ./tempFolder
 4.0K   ./Folder1
 36K    .
36K total

3 Answers 3

2

In the output of du -ch, the last line is the total you asked for with -c while the second to last line is the total size of the directory you queried.

In your case of running du without a specified directory it uses ., otherwise known as the current directory. The full size of a single queried directory is usually also the total size. You would normally use the -c option when you want the total size of multiple directories passed to the du command, i.e. du -ch /opt /srv /etc

Also, the output of du -ch does not show sizes of individual files, just their totals in the directory. Without knowing the contents of the directory associated with that output, I would assume you have 28k of regular files in that folder as well as those two directories.

1
  • In those 28K, there's also the directory file (.) itself. May 1, 2018 at 11:06
2

By default, du shows size counts for only directories as a whole; the counts of files (non-directories to be exact) are not shown individually but their sizes are obviously counted and added up to the size count of their parent directory.

So, in:

4.0K   ./tempFolder
4.0K   ./Folder1
36K    .
36K total
  • du is showing size count for the current directory (as without any filesystem path argument, it defaults to .), recursively -- totaling in 36K
  • directories ./tempFolder and ./Folder1 -- both has sizes of 4K individually (again calculated recursively)

As a side note, to make du to show the size for individual files as well, use -a/--all:

-a, --all
    write counts for all files, not just directories
2

You can try this way.

du -ch location  | grep total
1
  • Welcome to the site, and thank you for your contribution. Please note, however, that the OP does not want to isolate the grand total from the output of du, but wants to understand how this value is calculated (in particular given that it is not simply the sum of all values on the lines above the total).
    – AdminBee
    Aug 5, 2020 at 8:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .