Super User is a question and answer site for computer enthusiasts and power users. 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

I have 2 folders that have subfolders (named after users). Most subfolder names exist in both folders, but not all. Now I want to create a list of space used by each user.

I can use the following command to get a list for each folder,

du -m --max-depth=1 | sort -nr

but I don't know an easy way to merge two of these lists. Not all users have a folder in both places, so simple sorting does not work. Any idea on how to sum up the folder sizes for each user?

share|improve this question
I don't quite get your folders structure. Could you give a simple example to clarify? – Patkos Csaba Sep 28 '10 at 13:45
up vote 3 down vote accepted

Give this a try:

join -j 2 <(cd dir1; du -m --max-depth=1 | sort -k2,2) <(cd dir2; du -m --max-depth=1 | sort -k2,2) | awk '{print $2 + $3, $1}' | sort -nr

It should look like this:

11 ./bob
9 ./jan
8 ./cheryl
3 ./mike

You can change the AWK command to make the output a little more attractive:

awk '{printf "%6s\t%s\n", $2 + $3, $1}'

which will right-align the numbers and make the names line up in a column.

share|improve this answer
Thanks, this works perfectly. I didn't know about the join command, that's really handy. – Mad Scientist Sep 29 '10 at 7:27

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.