2

I am using indicator-multiload and would like it to show the Free Disk Space in my Partitions.

So, I went through the code, and found out that the author was parsing the contents of /sys/block/(device)/stat to get the read and write speeds. (where 'device' can be sda etc.).

I looked around sys/block and couldn't find anything useful that could give me info about free space in a disk. Although /sys/block/sda/size gives the total available space, I couldn't find an entry for free space.

I want to know if there is a file in the linux system which explicitly stores free space information.

If not, can you suggest a way on how I could get an indicator with stats on free disk space.

2 Answers 2

3

The free space isn't a property of the block device - it's a property of the filesystem on the device. Consequently, there won't be anything useful under /sys/block. Fortunately, there are other ways to query this information.

From the shell, one of the easiest ways to get the current free space is by using df:

[jk@pecola sda2]$ df -h /dev/sda[123]
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        64M  117K   64M   1% /boot/efi
/dev/sda2        20G  9.7G  9.4G  51% /
/dev/sda3        92G   65G   23G  75% /home

This uses the statfs system call to determine the free space available; if you're writing code to query free space, I'd suggest reading the statfs manpage:

man statfs

Hope this helps!

1
  • Note that obviously, df can only show info for mounted devices, since the info has to come from the filesystem.
    – mivk
    Mar 12, 2013 at 23:53
0

You can find this information using the df command at the terminal (df -H for a more readable output).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .