int main() {
char buf[100];
FILE *fp = popen("df -P /myLoc", "r");
while (fgets(buf, 100, fp) != NULL) {
printf( "%s", buf);
}
pclose(fp);
return 0;
}
Output:
Filesystem 512-blocks Used Available Capacity Mounted on
/dev0/vol0 123456 3456 5464675 4% /sys
I got the output of command in buf variable. But I need to get the value of Capacity (4 in this case) into an integer variable. I think cut or awk command can be used but not sure how to make it work exactly.
Any help is appreciated.
df -P | awk '{print $5}'work for you?fstatfsorstatfsis better option than running thedfcommand.