When you type in ls -l, there is a number on the first line labeled "total 22037"? What does this number mean? I am attempting to write my own version of ls -l( in C), and how do I get this value or calculate it?

Thanks for any help.

  • 3
  • Was just going to post the same question as sinclair. For implementation, you can ask in SO.
    – user8
    Mar 25, 2016 at 18:56
  • These are two completely different questions. The second (implementation) belongs on SO. The first could fit here, but it's already been answered quite well on SO, as linked above.
    – Wildcard
    Mar 25, 2016 at 19:59

1 Answer 1


To implement standard UNIX command, you should check POSIX, e.g. at http://pubs.opengroup.org/onlinepubs/9699919799/. For ls command: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html you will find the format of output:

If any of the -l, -n, -s, -g, or -o options is specified, each list of files within the directory shall be preceded by a status line indicating the number of file system blocks occupied by files in the directory in 512-byte units if the -k option is not specified, or 1024-byte units if the -k option is specified, rounded up to the next integral number of units, if necessary. In the POSIX locale, the format shall be:

"total %u\n",

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