What is difference between ls -lh and du -sh?
5,273
The du
command shows how much disk space is used for the given file.
In contrast, the ls
command shows the size of the file. The space used can be larger than the file size, depending on the filesystem used.
For example, we can create a file with the size 1 byte like this (just one newline character in the file):
echo > tmp.txt
Then check its size using ls -l
which shows the size one byte:
ls -l tmp.txt
-rw-r--r-- 1 elias elias 1 aug 6 17:50 tmp.txt
Then check the used space using du:
du -h tmp.txt
4,0K tmp.txt
So the used disk space was in this example 4 kilobytes, although the filesize is only one byte.
Related videos on Youtube
Author by
Nitin Kumar
Updated on September 18, 2022Comments
-
Nitin Kumar over 1 year
$ ls -lh file1.tar -rw-r--r-- 1 wnice wnice 40K Aug 6 20:41 file1.tar $ du -sh file1.tar 80K file1.tar
Why is it showing different sizes of same file? Please help me understand
-
pLumo almost 5 yearsPossible duplicate of Why does ls -l output a different size from ls -s?
-
pLumo almost 5 yearsDuplicate is not
du
vsls
, butls
vsls -s
. The answer is the same. -
pLumo almost 5 years
-
Terrance almost 5 years
-
VictorLee almost 3 years
-
-
Terrance almost 5 yearsdu is showing the block size and since the file size is smaller than the 4K block size it will only show you the 4K. If the file was 5K in size it would now show 8K being used.
sudo blockdev --getbsz /dev/sda1
should show the block size of the drive being used. -
Admin almost 2 yearsNone of that explains why a file that is 40K in size would occupy 80K of disk space.