How do I see how many blocks I have free on my filesystem?

11,957

If you have a 1K file occupying a 4K filesystem block, it will contribute 4K to the df output.

df calculates the number by asking the kernel for the free block count (with statfs/statvfs) and multiplying that by block size / 1024.

Just divide by 4. Sometimes things are simpler than you expect.

On the other hand, you shouldn't assume every version of df uses 1024-byte blocks as its reporting unit. Sometimes it's 512.

Share:
11,957

Related videos on Youtube

cat pants
Author by

cat pants

Updated on November 26, 2022

Comments

  • cat pants
    cat pants over 1 year

    I know df is supposed to provide this information, but when I run df it shows the number of 1k blocks free, yet my filesystem is using 4k blocks.

    I could simply divide by four of course, but this wouldn't necessarily be correct, due to the difference in granularity. For example, four 1k files would use four 1k blocks on a filesystem using 1k blocks, but four 1k files would use four 4k blocks on a filesystem using 4k blocks. (So dividing by four would produce the wrong answer.)

  • Admin
    Admin almost 10 years
    df explicitly states in the first line of output that it is using 1k blocks. Sounds good! I'll just divide by 4 then. I just found it strange that df wouldn't attempt to use the correct block size per filesystem.