title: How can I iterate over the contents of a directory in unix without using a wildcard?
body: <p>I totally understand what the problem is here.  </p>
  
  <p>I have a set of files, prepended as 'cat.jpg' and 'dog.jpg.'  I just want to move the 'cat.jpg' files into a directory called 'cat.' Same with the 'dog.jpg' files.  </p>
  
  <pre><code>for f in *.jpg; do
      name=`echo "$f"|sed 's/ -.*//'`
      firstThreeLetters=`echo "$name"|cut -c 1-3`
      dir="path/$firstThreeLetters"
      mv "$f" "$dir"
  done
  </code></pre>
  
  <p>I get this message:  </p>
  
  <p><code>mv: cannot stat '*.jpg': No such file or directory</code>  </p>
  
  <p>That's fine.  But I can't find any way to iterate over these images without using that wildcard.  </p>
  
  <p>I don't want to use the wildcard. The only files are prepended with the 'dog' or 'cat'. I don't need to match. All the files are .jpgs.  </p>
  
  <p>Can't I just iterate over the contents of the directory without using a wildcard?  I know this is a bit of an XY Problem but still I would like to learn this.</p>