title: Calculate size of files in shell
body: <p>I'm trying to calculate the total size in bytes of all files (in a directory tree) matching a filename pattern just using the shell. This is what I have so far:</p>
  
  <blockquote>
    <p>find -name *.undo -exec stat -c%s {} \; | awk '{total += $1} END {print total}'</p>
  </blockquote>
  
  <p>Is there an easier way to do this? I feel like there should be a simple du or find switch that does this for me but I can't find one.</p>
  
  <p>To be clear I want to total files matching a pattern anywhere under a directory tree which means</p>
  
  <blockquote>
    <p>du -bs *.undo</p>
  </blockquote>
  
  <p>won't work because it only matches the files in the current directory.</p>