Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

Is there a way to get the disk usage per user under a given path? du doesn't seem to have an option to aggregate disk usage per user, and df only seems to report how much disk is left on the drive.

Can this be done with one command or in a few lines on the shell? Any pointers would be greatly appreciated. In case it helps, I use zsh.

Note: Quotas are not enabled on our filesystem.

share|improve this question
Are quotas enabled on your filesystem? – jordanm May 29 '13 at 14:13
@jordanm no. They are not. I will clarify this in the OP – Amelio Vazquez-Reina May 29 '13 at 14:14
up vote 9 down vote accepted

The following will work with GNU find and awk:

find /path -type f -printf '%u %k\n' | awk '{ 
                                            arr[$1] += $2 
                                        } END { 
                                            for ( i in arr ) { 
                                                print i": "arr[i]"K" 
share|improve this answer

You can take advantage of zsh's stat builtin.

zmodload zsh/stat
local -a stat
local -A usage
local x
for x in **/*(.); do
  stat -A stat -- $x
  ((usage[$stat[5]] += stat[8]))
for x in ${(k)usage}; do
  echo $usage[$x] ${${"$(getent passwd $x)"%%:*}:-$x}
done | sort -k1n

(getent to retrieve the username from the user ID is specific to Linux, I don't think there's anything for that in zsh.)

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.