Main Content

How much space does my directory take - Linux

Archive - Originally posted on "The Horse's Mouth" - 2009-07-20 15:30:15 - Graham Ellis

The index card in the library for "War and Peace" takes a lot less space that the book itself, and so it is when you ask Linux or Unix "how much space is taken in this directory" ... you'll be told how big each of the files are, and how big the index table for each subrirectory is. Here's an example from today's course, one of our training machines:

[trainee@easterton ~]$ ls -l
total 1224
drwxrwxr-x 4 trainee apache 4096 May 18 11:52 build
drwxrwxr-x 2 trainee apache 4096 Jun 4 11:56 dbn
drwxr-xr-x 2 trainee apache 4096 Jun 12 14:21 Desktop
-rwxr-xr-x 1 trainee apache 55 May 26 11:20 ls
drwxr-xr-x 3 trainee apache 4096 May 26 12:09 ppl
drwxr-x--- 2 trainee apache 4096 Jun 12 14:22 richard
-rw-r----- 1 trainee apache 81920 Jun 12 14:22 richard.tar
drwxr-x--- 3 trainee apache 4096 Jun 4 16:29 tombuild
-rw-r--r-- 1 trainee apache 22186 May 21 19:55 transwilts2009.odt
-rw-r--r-- 1 trainee apache 785849 May 21 19:55 transwilts_2009.pdf
-rw-r--r-- 1 trainee apache 313556 May 21 19:57 transwilts2009.pdf
drwxrwxr-x 4 trainee apache 4096 May 18 11:22 website


So that's telling me that the total size is 1224 Kbytes (just over 1 Mbyte) with most of the space in the file transwilts_2009.pdf. And there are 7 directories that are 4096 bytes each ... Yes, but that's the directory entry size. Let's dig deeper:

[trainee@easterton ~]$ du -sk *
211020 build
243080 dbn
12 Desktop
4 ls
60348 ppl
152 richard
84 richard.tar
60352 tombuild
24 transwilts2009.odt
772 transwilts_2009.pdf
312 transwilts2009.pdf
461424 website


Once again, you see that the transwilts_2009.pdf file is 772k ... but the grand total has rocketed from just over 1 Mbyte to 461 Mbytes ... because we're now looking within each directory. They're not 4096 bytes each - that's just the index card. The website directory (as an example) is 461 Mbytes alone.

Courses - Linux Admin Introduction and LAMP deployment for folks who have to look after we servers.