Why is that there is a difference in the file sizes as denoted in the screenshot i.e. the total file size under ls -lh is 44k whilst the size of the folder is only 4k? Am I reading it incorrectly?

- 1,892
- 9
- 27
- 28
2 Answers
Yep you are reading it wrong. 4.0K is the size on disk the the /tmp
folder entry takes up. It's generally always 4k (although can an will go up depending on certain factors). ls
also doesn't account for space taken up by the contents of the subfolder.
what you really want to look at is the du
command to get a good feel for total disk space.
gbeech@ny-man01:~$ ls -lh
total 3.6G
vs
gbeech@ny-man01:~$ du -sh
36G .

- 37,405
- 5
- 53
- 95
-
Thanks Zypher. That makes sense. When you say total disk space, what do you meant by that exactly? – PeanutsMonkey Jul 13 '11 at 20:34
-
@peanuts total disk space used in the current folder or on the system if you are on `/` so if you look at my two different results `~` is reported to use 3.6GB on that machine, but in reality it is 36GB as repoted by DU. – Zypher Jul 13 '11 at 20:39
-
Thanks Zypher. Sorry for being such a noob. I am still confused. When you say current folder, is that the folder I am currently in i.e. working directory? Also if I look at your example for 3.6GB and 36GB, does this mean that the home folder less its contents is 3.6GB large? – PeanutsMonkey Jul 13 '11 at 21:27
-
@Peanuts no worries. yep current folder = pwd. It means that the normal files in my home folder on that box are 3.6GB excluding the size of the files in sub folders. the 36Gb is the size of all normal files in my home folder tree. – Zypher Jul 13 '11 at 21:32
-
Thanks Zypher. Sorry I don't quite follow what you mean by `normal files` and `exluding the size of files in sub folder`. Do you mean that normal files are the files in the working directory hence the size of 3.6GB and 36GB relates to the combination of the normal files PLUS the files in the subfolders? – PeanutsMonkey Jul 13 '11 at 21:37
-
@Peanuts yep, under *nix everything is a file, directories are just special types of files. – Zypher Jul 13 '11 at 21:39
-
Ah right. So when you say `normal` files you are referring to files that display a - when I run the command ls -l and everything other file (be it a directory, block or character devices, etc) is a specila file. Is that right? – PeanutsMonkey Jul 13 '11 at 21:42
-
@PeanutsMonkey let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/802/discussion-between-zypher-and-peanutsmonkey) – Zypher Jul 13 '11 at 21:43
-
Sorry Zypher I can't seem to login in to chat. – PeanutsMonkey Jul 13 '11 at 22:16
The ls -lh
is giving you the size of the contents of /tmp
. The ls -ldh /tmp
is giving you the size of the directory file /tmp
which contains the information on the contents of /tmp
.
In Linux/Unix a directory is just a file containing information the d
switch says list the directoy entry, not it's contents.
Edit
If you want to know (approximately) how much disk space is being used by a set of files then du -h
will give you that. If you want to know the sum of the file sizes then du -b
will be more accurate.
e.g.
du -h
56K ./vmware-root
12K ./.font-unix
8.0K ./.ICE-unix
164K .
du -b
28474 ./vmware-root
4096 ./.font-unix
4096 ./.ICE-unix
68798 .
The output from du -b
corresponds to the output of
find . -ls | awk '{total += $7} END {print total}'
68798
which is the sum of the sizes of the files.

- 115,471
- 20
- 215
- 297
-
Just to be clear that when you say the size of the directory, it is the size of the directory and not of its contents? Is that right? – PeanutsMonkey Jul 13 '11 at 21:28
-
Yes, /tmp is just a file of type directory. When you ls -ldh /tmp you are getting the size of the file /tmp. – user9517 Jul 13 '11 at 21:34
-
Thanks Iain. So if I wanted to get the size of the directory and its contents i.e. normal files, subfolders, etc I would run the command du -h. Is that correct? – PeanutsMonkey Jul 13 '11 at 21:43
-
-
Thanks Iain. I take it that du -b is an accurate representation of the size of the files. – PeanutsMonkey Jul 13 '11 at 22:18