I would like to get individual file size, all used file size in the disk and usable the maximum file size in the disk. In linux, commands for checking file sizes such as "du", "df", "ls -l" are prepared.

However, the result is different when examining the total size of the files used in "df -h" and when examining the total size of the file used in "du -shc /*".

result of df,

$df -h
Filesystem      Size  Used Avail Use% Mounted on
ubi0:rootfs     435M  195M  240M  45% /
devtmpfs         88M  4.0K   88M   1% /dev
tmpfs           248M  168K  248M   1% /run
tmpfs           248M  124K  248M   1% /var/volatile

result of du,

$du -shc /*
3.3M    /bin
1.2M    /boot
4.0K    /dev
5.5M    /etc
38M     /home
9.7M    /lib
0       /media
0       /mnt
12K     /opt
0       /proc
168K    /run
2.5M    /sbin
0       /sys
0       /tmp
45M     /unit_tests
273M    /usr
228M    /var
36K     /www
605M    total

Which command shows the exact file size? Or, what other command can be executed to obtain the correct file size?

  • 2
    @ArpitAgarwal no, that’s not it at all. – Stephen Kitt Feb 20 '18 at 8:36
  • df shows filesystem usage. There can be only 1 file in block, so even if your file is 10 bytes it takes place of 4kB (may be other size depending on block size). On the other side du shows true file size (not the space it is occupying on disk). – DevilaN Feb 20 '18 at 10:34
find . -type f -printf "%s %p\n"
| improve this answer | |
  • wellcome to U&L, can you give more details ? like what printfdo ? how %var are used and so one. I'll happily upvote, then. – Archemar Feb 20 '18 at 10:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.