$ 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
$ 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
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.
sudo blockdev --getbsz /dev/sda1
should show the block size of the drive being used.
– Terrance
Aug 06 '19 at 16:25
du
vsls
, butls
vsls -s
. The answer is the same. – pLumo Aug 06 '19 at 15:29