How to Check Disk Quota vs Available Space on Linux Systems


10 views

When managing disk space on Linux systems, many developers confuse the output of df with their actual disk quota. While df -h shows available space on the filesystem, it doesn't reflect user/group quotas that might be enforced by the system administrator.

For systems with quotas enabled, you'll need specific commands:

# For user quotas:
quota -vs

# For group quotas:
quota -vsg

# Alternative commands that might work:
repquota -a
edquota -u $USER

Here's what you might see from quota -vs:

Disk quotas for user developer (uid 1001):
     Filesystem   space   quota   limit   grace   files   quota   limit   grace
      /dev/sda1    15G     20G     25G              12k      0       0

The key fields show:

  • space: Currently used
  • quota: Soft limit (you can temporarily exceed)
  • limit: Hard maximum
  • grace: Time remaining if over soft limit

If the system doesn't have quota tools installed, check for these alternatives:

# Check if quota is enabled on a filesystem:
cat /proc/mounts | grep quota

# Modern systems might use:
systemctl list-units --type=service | grep quota

For regular monitoring, you might want a script like this:

#!/bin/bash
CURRENT=$(quota -vs | awk '/\/dev/ {print $2}')
LIMIT=$(quota -vs | awk '/\/dev/ {print $4}')
PERCENT=$((100*$CURRENT/$LIMIT))

if [ $PERCENT -gt 90 ]; then
    echo "Warning: Disk usage at $PERCENT% of quota"
fi

When working on shared Linux systems or managed servers, you'll often encounter two different disk space measurements:

  • df shows physical disk usage across the entire filesystem
  • Quota represents your allocated space limit as a user

For systems with quota enforcement, use these commands:


# Basic quota check
quota -v

# More detailed output (requires admin privileges)
repquota -a

On newer Linux distributions with cgroups v2:


# Check your user.slice disk limits
systemd-cgtop
cat /sys/fs/cgroup/user.slice/user-$(id -u).slice/user@$(id -u).service/memory.current

For AWS EC2 instances with EBS volumes:


# Check both physical space and provisioned IOPS
df -h
aws ec2 describe-volumes --volume-ids vol-1234567890abcdef0 --query 'Volumes[0].{Size:Size,IOPS:Iops}'

For Google Cloud persistent disks:


gcloud compute disks describe DISK_NAME --zone ZONE --format="value(sizeGb,physicalBlockSizeBytes)"

Here's a Python script to check and alert when nearing quota limits:


import subprocess
import shlex

def check_quota():
    cmd = "quota -w | grep -A1 'Filesystem' | tail -n1"
    output = subprocess.run(shlex.split(cmd), capture_output=True, text=True)
    parts = output.stdout.split()
    
    used = int(parts[2])
    limit = int(parts[3])
    percent = (used/limit)*100
    
    if percent > 90:
        print(f"WARNING: Quota usage at {percent:.1f}%")
    return percent

if __name__ == "__main__":
    check_quota()

If standard quota commands aren't installed, try these alternatives:


# Check home directory limits (common on HPC systems)
lfs quota -h /home/$USER

# Docker container disk limits
docker system df -v