linux check used space in folder

To check the used space in a folder on Linux using C language, you can use the statvfs function from the sys/statvfs.h header file. Here's an example code snippet:

#include <stdio.h>
#include <sys/statvfs.h>

int main() {
    char path[] = "/path/to/folder";

    struct statvfs stat;
    if (statvfs(path, &stat) == 0) {
        unsigned long long total_size = stat.f_blocks * stat.f_frsize;
        unsigned long long free_size = stat.f_bfree * stat.f_frsize;
        unsigned long long used_size = (stat.f_blocks - stat.f_bfree) * stat.f_frsize;

        printf("Total space: %llu bytes\n", total_size);
        printf("Free space: %llu bytes\n", free_size);
        printf("Used space: %llu bytes\n", used_size);
    } else {
        printf("Failed to get folder information.\n");
    }

    return 0;
}

Replace "/path/to/folder" with the actual path of the folder you want to check. The code uses the statvfs function to obtain information about the filesystem containing the specified path, and then calculates the total, free, and used space in bytes.

Note that the code assumes that the folder path is valid and accessible. Make sure to handle any errors that may occur, such as when the folder does not exist or the user does not have sufficient permissions to access it.