title: Reading files in order in BASH script
body: <p>So I've got a bash script that greps a series of subdirectories, looking for files that contain a certain string, and then printing file totals and directory totals for the string's occurences. The code is as follows.</p>
  
  <pre><code>  for dir in $(find * -type d); do
    echo "directory: $dir" &gt;&gt; $OUT
    for f in $(find $dir/* -type f); do
      echo -n "$(basename $f) " &gt;&gt; $OUT
      grep -c -h $1 $f &gt;&gt; $OUT
    done
    echo -n "directory total: " &gt;&gt; $OUT
    grep -c -h $1 $dir/*.* | awk '{SUM += $1} END {print SUM}' &gt;&gt; $OUT
    done
  </code></pre>
  
  <p>When it does this, if I read in 10 files, it lists them in the text file as <strong>file1.txt, file10.txt, file2.txt</strong> etc...</p>
  
  <p>Is there any way I could make it print file1.txt, file2.txt, file3.txt etc and have the 10th file be actually listed in order? </p>
  
  <p>I'm new to BASH so I was just wondering if any knew anything about this. Any help greatly appreciated. And yes, the files are literally named file1.txt, file2.txt etc. This is mostly just to familiarize myself with BASH scripting.</p>