Linux 精确获取指定目录对应的块的剩余空间
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/statfs.h> int main(int argc,char *argv[]) { if(argc<2) { printf("please print one param !\n"); return 0; } char buf[1024]={0}; char tmp[1024]={0}; sprintf(tmp,"df %s | sed -n '3p'|awk '{print $3}'",argv[1]); FILE * file=popen(tmp,"r"); int count=0; if(file!=NULL) { if(fgets(buf,1024,file)!=NULL) { long long freesize= strtoll(buf,NULL,10); printf("size=%lld\n",freesize); } } return 0; }