38

When I do ls -l I get this:

calico@A000505:~/Documentos$ ls -l
total 2020
-rwxr-xr-x 1 calico calico    8559 2010-11-16 11:12 a.out
-rwxrw-rw- 1 smt    smt    2050138 2010-10-14 10:40 Java2.pdf
-rwxrw-rw- 1 ocv    ocv        234 2010-11-16 11:11 test.c

But what does the "total 2020" mean? I only have 3 files so it's not the number of files or directories, and I guess it's not the size either. So what is it?

3 Answers 3

31

The number of 1kB blocks used by the files in the directory, non-recursively.

Use ls -lh to have some more meaningful output.

2
  • 7
    More precisely, on most implementations, this is the total number of blocks used by files included in the directory listing (compare ls -l ~ with ls -la ~, and ls -lA ~). The block size is 1kB with GNU tools, but 512B according to POSIX and most other current implementations. Commented Nov 16, 2010 at 19:37
  • What does -h do?
    – anon
    Commented Jul 3, 2018 at 21:39
17

what does "total" mean in ls -al

Great question, it means you want to pay attention to detail. I'll illustrate with examples. Under my home directory /home/el there is a directory called tmpdir with files underneath it. I change to that directory and do ls -al

el@angeliqe ~/tmpdir $ ls -al
total 20
drwxrwxr-x 4 el users 4096 Dec 21 11:45 .
drwx--x--x 9 el users 4096 Dec 21 11:45 ..
drwxrwxr-x 2 el users 4096 Dec 21 11:45 dirWithFiles
drwxrwxr-x 2 el users 4096 Dec 21 11:44 emptydir
-rw-rw-r-- 1 el users  182 Dec 21 11:45 myfile.txt

It says 'total 20'. That translates to: "tmpdir uses 20K of space on disk for all of the directories and files".

with the -h option, you tell it to give it to you in human readable form:

el@angeliqe ~/tmpdir $ ls -alh
total 20K
drwxrwxr-x 4 el users 4.0K Dec 21 11:45 .
drwx--x--x 9 el users 4.0K Dec 21 11:45 ..
drwxrwxr-x 2 el users 4.0K Dec 21 11:45 dirWithFiles
drwxrwxr-x 2 el users 4.0K Dec 21 11:44 emptydir
-rw-rw-r-- 1 el users  182 Dec 21 11:45 myfile.txt

It is interesting to note that a directory with nothing in it also takes up 8K space, in my case emptydir has nothing in it but shows as using 8K

el@angeliqe ~/tmpdir/emptydir $ ls -al
total 8
drwxrwxr-x 2 el users 4096 Dec 21 11:44 .
drwxrwxr-x 4 el users 4096 Dec 21 11:45 ..

Adding an empty directory proves that directories take up 4K:

el@angeliqe ~/tmpdir/emptydir $ ls -alh
total 12K
drwxrwxr-x 3 el users 4.0K Dec 21 11:54 .
drwxrwxr-x 4 el users 4.0K Dec 21 11:45 ..
drwxrwxr-x 2 el users 4.0K Dec 21 11:54 blah

Another command to investigate is du:

el@angeliqe ~/tmpdir/emptydir $ du
4       ./blah
8       .

Also, you can look at file sizes to a certain depth:

el@angeliqe ~ $ du -h --max-depth=1
12K     ./.ssh
4.0K    ./my_recycle_bin
8.0K    ./.vim
13G     ./gnuoctbluehost
24K     ./tmpdir
48K     ./.subversion
152K    ./.cpan
13G     .
el@angeliqe ~ $
1
  • K refers to kilobyte or kibibyte? Commented Nov 13, 2022 at 14:59
6

Nobody mention about -s option(?). From man ls:

-s, --size print the allocated size of each file, in blocks

.. so if you list with ls -s then you will get number of blocks for each directory and file in current directory. When you summarize it then you will get exactly the same number as in total: you see on top of ls -l.

Extra: To get block size check this.

You must log in to answer this question.

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