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 this structure in my linux filesystem:


And I want to get the total disk space that all the temp/ folders are using. I suppose it's something with df or du, but no idea on how to achieve it. I only need the sum of all the temp/ directories, not the other folders or files that may be in the subfolders. Any idea?


share|improve this question

migrated from Oct 17 '11 at 21:40

This question came from our site for professional and enthusiast programmers.

retagged bash so it doesn't get flagged for Serverfault (although you'll probably find a better answer there) – Louis Oct 17 '11 at 21:02
The first line of the du manpage says 'Description: Summarize disk usage of each FILE, recursively for directories.' Using the du command without any flags should do the trick. – Nick ODell Oct 17 '11 at 21:04

You can use the below command to get the size of each temp directory and the grand total:

du -csh /folder/*/temp
share|improve this answer
this one worked perfectly!! thank you! – shirkkan Oct 17 '11 at 21:35
@shirkkan: Please accept this answer if it is the best solution to your problem – MattH Oct 18 '11 at 7:29

I like Siavash's solution, it provides the total size on disk (in block increments).

Here's a byte count of files using find and awk:

find /folder -type f -wholename '*/temp/*' -printf '%s\n' | awk '{ total += $1 } END { print "Total:", total }'
share|improve this answer

Try this:

for i in $(du -b | grep "/temp$" | cut -f1); do
        totalsize=$((totalsize + i))

totalsize=$(echo $totalsize | awk '{sum=$1; hum[1024**3]="Gb";hum[1024**2]="Mb"; hum[1024]="Kb"; for (x=1024**3; x>=1024; x/=1024){ if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x];break }}}')

echo "Total size: $totalsize"

It looks for every folder path that ends with /temp, and shows only the size in bytes. For each size found, add it to the total, and then before printing the results, use awk to convert bytes into human readable format.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.