Linux – Any way to limit disk usage on a per directory level

filesystemslinux

I know I can use quota to limit the amount of disk space per user. However I'm wondering if there's some way in Linux to limit the disk usage of a directory? Ideally I'd like something like

limit_space -n 100M ./path/to/directory

And any attempts to create a file or write to a file that would make it more than 100MB would fail with a similar error as if you tried to write to a full disk.

I know it gets complicated because of symlinks and hardlinks and block sizes and stuff.

The reason I'm asking is that I have a programme that downloads files to a temporary directory, and I want to test that that it does the right thing if it can't write the file. Simulating a full disk would be one of the ways. If there's a quick one-liner like this, then I can test this easily.

Best Answer

If this is just for testing purposes, I suggest you create a smallish loopback filesystem and mount it at the place you want test full disks.

Related Topic