Linux文件夹大小

发布于 2024-09-16 06:25:13 字数 168 浏览 1 评论 0原文

我需要定期监视我的 Linux 机器上的文件夹,以检查它们是否超出了某些限制。

我已经检查了 stat 函数调用,但在所有子文件夹和文件上递归运行 stat 非常耗时,我需要对所有文件夹执行此操作。

kernal 是否维护我可以在程序中解释的任何数据结构。或者他们是否有任何标准 api。

I need to monitor folders on my linux machine periodically to check whether they are exceeding certain limits.

I have checked stat function call but running stat recursively on all sub folders and files is time consuming and I need to do this for all folders.

Does kernal maintain any datastructures which I can interpret in my program.Or is their any standard api for this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

雨后彩虹 2024-09-23 06:25:13

如果您需要强制执行限制,请使用配额

If you need to enforce limits then use quotas

追我者格杀勿论 2024-09-23 06:25:13

如果配额机制不合适,那么
inotify 可能很方便:

来自维基百科:

inotify是一个Linux内核子系统
其作用是将文件系统扩展到
注意文件系统的更改,以及
将这些更改报告给应用程序。将这些更改报告给应用程序。

In case the quota mechanism isn't suitible, then
inotify might be handy:

From wikipedia:

inotify is a Linux kernel subsystem
that acts to extend filesystems to
notice changes to the filesystem, and
report those changes to applications.report those changes to applications.

Oo萌小芽oO 2024-09-23 06:25:13

类型

du -sm directory_name

将递归地给出目录的总大小(以兆字节为单位)。

键入

man du

以获取有关此命令的帮助。

Type

du -sm directory_name

Will give you the total size of the directory in megabytes recursively.

Type

man du

for help with this command.

几味少女 2024-09-23 06:25:13

你想要 quotactl:

quotactl -- manipulate filesystem quotas

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

You want quotactl:

quotactl -- manipulate filesystem quotas

SYNOPSIS
     #include <sys/types.h>   /* types needed by quota.h */
     #include <sys/quota.h>   /* for disk quotas */
心奴独伤 2024-09-23 06:25:13

递归调用 stat 是获取当前文件夹大小的唯一方法。如果你想持续监控文件系统,可以看看inotify。

Calling stat recursively is the only way to get the current folder size. If you want to continuously monitor the file system, take a look at inotify.

影子是时光的心 2024-09-23 06:25:13

我同意@Axel 的观点。但是,如果您确实需要在代码中执行此操作,则可以通过 popen 执行 du shell 命令:

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

然后通过文件句柄和 fgets(...) 读取命令的输出

I agree with @Axel. However if you really need to do this in code, you could execute the du shell command via popen:

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

Then read the output from the command via the file handle and fgets(...)

从﹋此江山别 2024-09-23 06:25:13

使用命令 du,检查此链接...
"如何检查文件夹大小”

Use command du, check this link ...
"How To Check Folder Size"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文