Linux folder size

I need to periodically monitor folders on my Linux machine to see if they exceed certain limits.

I checked the stat function call, but works recursively in all subfolders, and the files take a lot of time, and I need to do this for all folders.

Does the kernel support any data structures that I can interpret in my program? Or is it their any standard api for this.

+3
source share
7 answers

If you need to enforce limits, use quotas

+3
source

If the quota mechanism is not suitable, then inotify may be convenient:

:

inotify - Linux . .

+3

du -sm directory_name

.

man du

.

+2

quotactl:

quotactl -- manipulate filesystem quotas

SYNOPSIS
     #include <sys/types.h>   /* types needed by quota.h */
     #include <sys/quota.h>   /* for disk quotas */
+1

- . , inotify.

+1

@Axel. , , du popen:

FILE* pf = popen("du -ch [your folder] | grep total")

fgets (...)

0
source

Use du command, check this link ... "How to check folder size"

0
source

Source: https://habr.com/ru/post/1761504/


All Articles