Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
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.

share|improve this question

migrated from stackoverflow.com Aug 22 '10 at 4:35

This question came from our site for professional and enthusiast programmers.

1  
You 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 Aug 20 '10 at 8:16
add comment

2 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.