title: What's wrong with my these two Bash pipeline methods for counting average file size in a directory?
body: <p>The problem: I am trying to calculate an average file size for the directory I'm in (ignoring sub-directories) using one-liners. I have two methods:</p>
  
  <pre><code>ls -l | gawk '{sum += $5; n++;} END {print sum/n;}'
  </code></pre>
  
  <p>and </p>
  
  <pre><code>var1=$(du -Ss| awk '{print $1}') ; var2=$(ls -l | wc -l) ; echo $var1/$var2 | bc
  </code></pre>
  
  <p>They seem to yield similar numbers, albeit different units (first one in kB, second one in MB). </p>
  
  <p>The numbers themselves however are slightly wrong. What's going on? Which one is more right?</p>