Nitin Kumar Asked: 2019-08-07 07:17:44 +0800 CST2019-08-07 07:17:44 +0800 CST 2019-08-07 07:17:44 +0800 CST What is difference between ls -lh and du -sh? 772 $ 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 files ls df du 1 Answers Voted Elias 2019-08-07T07:57:27+08:002019-08-07T07:57:27+08:00 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.
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):
Then check its size using
ls -l
which shows the size one byte:Then check the used space using du:
So the used disk space was in this example 4 kilobytes, although the filesize is only one byte.