Take the 2-minute tour ×
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.

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 –  user815423426 May 29 '13 at 14:14

2 Answers 2

up vote 8 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]))
done
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

 
discard

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.