I have written a C program to display basic system info. It does this by parsing /etc/network/interfaces and /proc/meminfo with fgets and associated logic. These give me the network info and memory/RAM info, but is there an additional location where I can extract the available disk space and the total disk space in my program?

2 Answers 2


You can get disk size reading the file /sys/proc/sda/size, it will give you a number like 976773168. Take that number and multiply it by 512 and get the size in bytes. From there, you can convert it to MB's or GB's.

Also you can get the size of partitions size reading /sys/block/sda/sdaX/size.


The command df -h shows disk free and used space for every mount in human readable sizes.

The command du -sh /* | sort -n -r will show how much space is used by every top level directory.

You must log in to answer this question.

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