2

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

0

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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