Why does ls -lh and ls -ldh give me varying file size?
772
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?
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.
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
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.vs
The
ls -lh
is giving you the size of the contents of/tmp
. Thels -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 thendu -b
will be more accurate.e.g.
The output from
du -b
corresponds to the output ofwhich is the sum of the sizes of the files.