Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 3247  / 2 Years ago, sun, june 19, 2022, 9:51:48

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.


More From » disk-usage

 Answers
2

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!


[#37498] Monday, June 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
turhizz

Total Points: 82
Total Questions: 106
Total Answers: 96

Location: South Korea
Member since Mon, Dec 6, 2021
2 Years ago
turhizz questions
;