Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 6 down vote accepted

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.

share|improve this answer
Good call. Loopback filesystems are underappreciated for learning, experimenting and testing. – pboin Dec 12 '09 at 11:45

You can crate separate partition for this directory. If You don't want repartitioning your hard drive you can crate virtual partition with loop device (

//edit: this topic may interest You:

share|improve this answer

Have you considered using lvm for flexibility in having several virtual volumes (with the added bonus of hot backups, etc)?

(loopback filesystems are limited in number)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.