How to find user memory usage in linux

This one-liner worked at least four different Linux systems with different distros and versions.

echo "USER                 RSS      PROCS" ; echo "-------------------- -------- -----" ; ps hax -o rss,user | awk '{rss[$2]+=$1;procs[$2]+=1;}END{for(user in rss) printf "%-20s %8.0f %5.0f\n", user, rss[user]/1024, procs[user];}' | sort -rnk2

 

USER                 RSS      PROCS
-------------------- -------- -----
admtest               1974930    11
root                     4544   736
gdm                        78    12
ntp                        14     1
postfix                     5     2
messagebus                  1     1
uuidd                       0     1