如何在 Linux 中设置目录大小限制?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8148715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 21:49:02  来源:igfitidea点击:

How to set limit on directory size in Linux?

linuxdirectorysizelimit

提问by user710818

I have read about limiting size of directory - like creating big files, formatting,mount,.. etc. But this all very complicated. Does exist utility or something else to set limit on already existing directory?

我已经阅读了限制目录大小的内容——比如创建大文件、格式​​化、挂载等。但这一切都非常复杂。是否存在实用程序或其他东西来设置对现有目录的限制?

采纳答案by Sergei Nikulov

Quota is based upon filesystems, but you can always create a virtual filesystem and mount it on a specific (empty) directory with the usrquota and/or grpquota flags.

配额基于文件系统,但您始终可以创建一个虚拟文件系统,并将其挂载到具有 usrquota 和/或 grpquota 标志的特定(空)目录中。

In steps this will be:

在步骤中,这将是:

  1. create the mount point
  2. create a file full of /dev/zero, large enough to the maximum size you want to reserve for the virtual filesystem
  3. format this file with an ext3 filesystem (you can format a disk space even if it is not a block device, but double check the syntax of every - dangerous - formatting command)
  4. mount the newly formatted disk space in the directory you've created as mount point, e.g. Code: mount -o loop,rw,usrquota,grpquota /path/to/the/formatted/disk/space /path/of/mount/point
  5. Set proper permissions
  6. Set quotas and the trick is done.
  1. 创建挂载点
  2. 创建一个充满 /dev/zero 的文件,该文件足够大到您希望为虚拟文件系统保留的最大大小
  3. 使用 ext3 文件系统格式化此文件(即使它不是块设备,您也可以格式化磁盘空间,但请仔细检查每个 - 危险 - 格式化命令的语法)
  4. 在您创建的目录中挂载新格式化的磁盘空间作为挂载点,例如代码: mount -o loop,rw,usrquota,grpquota /path/to/the/formatted/disk/space /path/of/mount/point
  5. 设置适当的权限
  6. 设置配额,诀窍就完成了。

Tutorial here. Original answer here

教程在这里。原答案在这里

回答by Basile Starynkevitch

You could limit the quotaon a filesystem. But it is not directory specific, but file system & user specific.

您可以限制文件系统上的配额。但它不是特定于目录的,而是特定于文件系统和用户的。

You might also consider developping your own user space file system using FUSE, but this will take your time.

您也可以考虑使用FUSE开发您自己的用户空间文件系统,但这需要您的时间。