Linux文件夹大小
我需要定期监视我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果您需要强制执行限制,请使用配额
If you need to enforce limits then use quotas
如果配额机制不合适,那么
inotify 可能很方便:
来自维基百科:
In case the quota mechanism isn't suitible, then
inotify might be handy:
From wikipedia:
类型
将递归地给出目录的总大小(以兆字节为单位)。
键入
以获取有关此命令的帮助。
Type
Will give you the total size of the directory in megabytes recursively.
Type
for help with this command.
你想要 quotactl:
You want quotactl:
递归调用 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.
我同意@Axel 的观点。但是,如果您确实需要在代码中执行此操作,则可以通过 popen 执行 du shell 命令:
然后通过文件句柄和 fgets(...) 读取命令的输出
I agree with @Axel. However if you really need to do this in code, you could execute the du shell command via popen:
Then read the output from the command via the file handle and fgets(...)
使用命令 du,检查此链接...
"如何检查文件夹大小”
Use command du, check this link ...
"How To Check Folder Size"