How do I interpret “total 18” in the output of the "ls -l" command in Solaris10?

2

auyantepui# ls -l
total 18
drwxr-xr-x   2  root sys   512  May 23 13:11  READMEs/
drwxr-xr-x   2  root sys  1024  May 23 13:11  bin/
drwxr-xr-x   2  root sys   512  May 23 13:09  docs/
drwxr-xr-x   2  root sys   512  May 23 13:09  examples/
drwxr-xr-x   3  root sys   512  Mar 31 2004   inventory/
drwxr-xr-x   4  root sys  1536  May 23 13:11  lib/
drwxr-xr-x  11  root sys   512  May 23 13:11  man/
drwxr-xr-x   6  root sys   512  May 23 13:11  prod/

In this command, what does the “total 18” mean? Please explain in detail.

pandusol

Posted 2010-08-20T08:13:39.557

Reputation:

2You should probably ask this over on superuser.com. It's not really a programming question. You might want to, however, as a hint, check out man ls for details. – JUST MY correct OPINION – 2010-08-20T08:16:39.923

Answers

4

It is the total disk allocation for the contents of this directory:

‘-l’
‘--format=long’
‘--format=verbose’

In addition to the name of each file, print the file type, permissions, number of hard links, owner name, group name, size, and timestamp (see section 10.1.6 Formatting file timestamps), normally the modification time.

Normally the size is printed as a byte count without punctuation, but this can be overridden (see section 2.2 Block size). For example, ‘-h’ prints an abbreviated, human-readable count, and ‘--block-size="'1"’ prints a byte count with the thousands separator of the current locale.

For each directory that is listed, preface the files with a line ‘total blocks, where blocks is the total disk allocation for all files in that directory. The block size currently defaults to 1024 bytes, but this can be overridden (see section 2.2 Block size). The blocks computed counts each hard link separately; this is arguably a deficiency.

...

Edit: variations of the above text can be found throughout the web.  This particular excerpt is copied from and linked to ftp://ftp.gnu.org/old-gnu/Manuals/coreutils/html_node/coreutils_54.html.

Colin HEBERT

Posted 2010-08-20T08:13:39.557

Reputation: 201

1

The real answer to the question lies buried, cryptically, in the last paragraph of the other response: “blocks is the total disk allocation for all files in that directory [where] the block size currently defaults to 1024 bytes …”  Directories count as files in this context.  Look at the sizes of the subdirectories (512, 1024, 512, …).  Round them all up to a multiple of 1024; you’ll get 1024, 1024, 1024, 1024, 1024, 2048, 1024, and 1024.  Now divide them all by 512 (the standard number of bytes in a disk sector), and you’ll get 2, 2, 2, 2, 2, 4, 2, and 2.  Add them and presto: 2+2+2+2+2+4+2+2=18.

Scott

Posted 2010-08-20T08:13:39.557

Reputation: 17 653