Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 12 down vote accepted

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

Use ls -lh to have some more meaningful output.

share|improve this answer
    
Thanks, I didn't know the h modifier, it's nice :) –  oli206 Nov 16 '10 at 13:18
3  
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. –  Gilles Nov 16 '10 at 19:37
add comment

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 ~ $
share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.