Disk Usage Summary per User in Zsh

disk-usagefilesuserszsh

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.

Best Answer

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" 
                                            }
                                        }'
Related Question