I have a lot of home folders under /home/ and I would like to get the total size of each users folder in an easy to read list.
ie
- /home/user1 100MB
- /home/user2 24MB
- /home/user3 54MB
etc.
Currently using something similar to
du -hc | grep total
I have a lot of home folders under /home/ and I would like to get the total size of each users folder in an easy to read list.
ie
etc.
Currently using something similar to
du -hc | grep total
du -hcs /home/*/
Or, for exactly what you want:
for i in /home/*/; do
user=${i#/*/}
space=$(du -hs "$i" | cut -f1)
echo "${user%/} = $space"
done
IMO, a merge of the answers by Ernie and Depesz is closest to what you asked for, except that it should be 'du -s /home/*/ | sort -n'. 'du -h' doesn't sort properly with 'sort -n', because it's not really a number any more, e.g. 10G sorts before 10M
another alternative, if you want to find out the total disk space used by each user regardless of whether it's in their home directory or not is to install the quota utils, enable quota accounting on the relevant filesystem(s), but leave each users' quota at 0 (unlimited). that will tell you disk space used as well as the number of files/inodes used.
then you can just run 'repquota -a' to get a report like this:
*** Report for user quotas on device /dev/sda8 Block grace time: 7days; Inode grace time: 7days Block limits File limits User used soft hard grace used soft hard grace user1 -- 67844 0 0 7748 0 0 user2 -- 21908 0 0 1742 0 0 user3 -- 27212 0 0 258 0 0 user4 -- 25492 0 0 328 0 0 user5 -- 575536 0 0 2972 0 0 user6 -- 83944 0 0 1114 0 0 user7 -- 501304 0 0 3418 0 0 user8 -- 760068 0 0 5011 0 0 user9 -- 1445396 0 0 1932 0 0 ...
repquota also has a "-s" option for "human readable" output, like du's "-h". not surprisingly, it has the same sorting problem as du -h, though.
What are you trying to find out?
If you're looking to sort by size, try this:
du -s /home/ |sort -n
just run this:
du -sh /home/*
And you should be happy.