cancel
Showing results for 
Search instead for 
Did you mean: 

difference btw output of ls -lh & du -h

Former Member
0 Kudos

  Dear experts,

ls -lh

drwxr-xr-x 2 prdadm sapsys 4.0K 2012-08-05 09:39 sumit

du -h

40K     ./sumit

As we know ls list total size of directory/file, here 't's 4.0k  and du shows space used ,

what's Differnce between 4.0k and 40k

Accepted Solutions (1)

Accepted Solutions (1)

former_member189725
Active Contributor
0 Kudos

4.0 K is the size of the directory sumit which means the space occupied by the metadata of the files of the directory . Any directory size with ls -lh is  4.0 K , with ls -l its always 4096 bytes.

ls -l only shows the exact size of the files , for directories its always 4096 bytes or 4.0K ( with ls -lh)

40 K on the other hand is the total space occupied by the contents of the directory sumit which is output of  du -h command.

Regards

Ratnajit

Former Member
0 Kudos

   Dear Ratnajit,

  f"or directories its always 4096 bytes or 4.0K ( with ls -lh)"

you mean, ls -lh always shows directories with 4.0K, but see below output for others directories:

drwxrwxrwx 2 prdadm sapsys 4.0K 2011-07-18 17:58 bin

drwxrwxrwx 2 prdadm sapsys 4.0K 2011-02-25 17:03 bin_backup

drwxrwxrwx 2 prdadm sapsys 4.0K 2011-07-18 18:25 buffer

drwxrwxrwx 2 prdadm sapsys 4.0K 2010-12-29 17:19 cluster_tables

drwxrwxrwx 2 prdadm sapsys 140K 2012-07-31 16:34 cofiles

drwxrwxrwx 2 prdadm sapsys 132K 2012-07-31 16:34 data

drwxrwxrwx 5 prdadm sapsys 4.0K 2012-08-05 07:55 EPS

drwxrwxrwx 2 prdadm sapsys 4.0K 2010-12-16 12:16 etc

-rw-rw-r-- 1 prdadm sapsys  380 2011-04-04 22:36 K926360.DEV

drwxrwxrwx 3 prdadm sapsys 260K 2012-08-05 07:56 log

drwxrwxrwx 2 prdadm sapsys  16K 2011-02-23 18:37 lost+found

drwxrwxrwx 2 prdadm sapsys 4.0K 2012-07-11 15:25 sapnames

drwxrwxrwx 2 prdadm sapsys 4.0K 2012-08-01 10:26 tm

former_member189725
Active Contributor
0 Kudos

Just a small clarification ,mostly you see directory sizes are of 4KB or 4096 bytes and this space is occupied by the metadata of files within this directory . If the number of files are really huge and hence the metadata is also large , then this value can be higher than 4 KB , but always in multiples of 4 KB. So space allocated for metadata of files within a directory is allocated in blocks of 4 KB. Hope this clarifies your doubt.

Regards

Ratnajit

Former Member
0 Kudos

     Dear Ratnajit,

  Thanks very much, Really much informative answer!!!!!!!!!!!!!

  So ,  you mean, We should use ls  -lh for files  & du -h for directories.

Also, let me what is metadata in above cases...........

former_member189725
Active Contributor
0 Kudos

Yes , ls -lh will give you size of files in KB whereas directory size is given by du -h .

By metadata , I mean the information about the files/directories within the directory.

Regards

Ratnajit

Former Member
0 Kudos

   Thanks a lot Ratnajit,  Your replies cleared all my doubts regarding this query.....

Superb knowledge u have!!! !   Keep It up!!!!!!

Answers (0)