When I do ls -l I get this:
<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="096a6865606a6649483939393c393c">[email protected]</a>:~/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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The number of 1kB blocks used by the files in the directory, non-recursively.
Use ls -lh to have some more meaningful output.
Method 2
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
<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="37525b77565950525b5e4652">[email protected]</a> ~/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:
<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9afff6dafbf4fdfff6f3ebff">[email protected]</a> ~/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
<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="62070e22030c05070e0b1307">[email protected]</a> ~/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:
<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="61040d21000f06040d081004">[email protected]</a> ~/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:
<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9df8f1ddfcf3faf8f1f4ecf8">[email protected]</a> ~/tmpdir/emptydir $ du 4 ./blah 8 .
Also, you can look at file sizes to a certain depth:
<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f1949db1909f96949d988094">[email protected]</a> ~ $ du -h --max-depth=1 12K ./.ssh 4.0K ./my_recycle_bin 8.0K ./.vim 13G ./gnuoctbluehost 24K ./tmpdir 48K ./.subversion 152K ./.cpan 13G . <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bdd8d1fddcd3dad8d1d4ccd8">[email protected]</a> ~ $
Method 3
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0