Skip to content

Instantly share code, notes, and snippets.

@turbo
Created July 6, 2017 14:04
Show Gist options
  • Save turbo/1dcf08ce958636cee7cd35672636e366 to your computer and use it in GitHub Desktop.
Save turbo/1dcf08ce958636cee7cd35672636e366 to your computer and use it in GitHub Desktop.
Quickly create a size-limited directory
#!/bin/bash
path=$1
sizelimit=$2
echo "Creating directory at $path, limited to $sizelimit MiB..."
mkdir "$path" 2>/dev/null || { exit; }
mkdir "/tmp/quotaimg" 2>/dev/null || { exit; }
dd if=/dev/zero of=/tmp/quotaimg/tmp.ext3 bs=1M count=$sizelimit
/sbin/mkfs -t ext3 -q /tmp/quotaimg/tmp.ext3 -F
sudo mount -o loop,rw,usrquota,grpquota /tmp/quotaimg/tmp.ext3 "$path"
# Delete with sudo umount "$path" && rm -rf /tmp/quotaimg
@turbo
Copy link
Author

turbo commented Jul 6, 2017

You can now also optionally apply user fs quotas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment