When administering multi-user Linux systems, monitoring individual disk consumption becomes crucial for resource allocation and troubleshooting. While df
shows filesystem-level usage and du
scans directories, neither directly provides user-specific data aggregation.
quota /h2>
For systems with disk quotas enabled:
# Check quota for all users
repquota -a
# User-specific report
quota -v username
Note: This requires pre-configured quotas and may not reflect actual usage in unquotaed systems.
find and du
/h2>
For comprehensive user-level reporting without quota setup:
# Single-line solution
find / -type f -printf "%u %s\\n" | awk '{user[$1]+=$2} END{for(u in user) printf "%s %.2fMB\\n",u,user[u]/1024/1024}'
# Human-readable format alternative
sudo du -sh /home/* 2>/dev/null | sort -h
For RHEL environments (as mentioned in your PS), this enhanced script handles edge cases:
#!/bin/bash
TMPFILE=$(mktemp)
# Scan all mounted filesystems excluding special types
awk '$2 ~ /^\\/$|\\/home|\\/var|\\/usr/ {print $2}' /proc/mounts | while read -r mount; do
find "$mount" -xdev -type f -printf "%u %s\\n" 2>/dev/null >> "$TMPFILE"
done
# Process results
awk '{
user[$1] += $2
total += $2
}
END {
for (u in user)
printf "%-15s %8.2f MB\\n", u, user[u]/1024/1024
printf "%-15s %8.2f MB\\n", "TOTAL", total/1024/1024
}' "$TMPFILE" | sort -k2nr
rm "$TMPFILE"
For large filesystems:
- Add
-xdev
to prevent crossing filesystem boundaries - Exclude virtual filesystems (
/proc
,/sys
) - Run during off-peak hours
For interactive exploration:
sudo ncdu -x / --exclude /mnt --exclude /media
Pro tip: Press 'g' to toggle between GB/MB display.
When administering a multi-user Linux system (particularly in enterprise environments like Red Hat Enterprise Linux), monitoring disk consumption per user becomes crucial for:
- Quota management
- Resource allocation
- Identifying storage hogs
- Capacity planning
While there's no single standard command, this robust combination gives precise results:
# Basic version for home directories
sudo du -sh /home/* | sort -hr
# Advanced version with user mapping
sudo find / -type f -user username -exec du -sh {} + | awk '{sum += $1} END {print sum}'
Here's a production-ready script that handles:
#!/bin/bash
# Output header
printf "%-15s %10s\\n" "USER" "USAGE(MB)"
# Process all users with home directories
for user in $(cut -d: -f1 /etc/passwd); do
home=$(eval echo "~$user")
if [ -d "$home" ]; then
size=$(du -sm "$home" 2>/dev/null | cut -f1)
[ -n "$size" ] && printf "%-15s %10s\\n" "$user" "$size"
fi
done
# Add total calculation
total=$(df -m --total | awk '/total/ {print $3}')
printf "\\n%-15s %10s\\n" "TOTAL" "$total"
For NFS Mounts
sudo du -sh /nfs_mount/* --exclude=/nfs_mount/lost+found | while read size user; do
echo "${user##*/} ${size}"
done
Using Extended Attributes (XFS)
sudo xfs_quota -x -c 'report -h' /mount_point
On large filesystems:
- Add
--time
to monitor execution duration - Use
nice -n 19
to reduce priority - Exclude virtual filesystems with
--exclude