title: How to tar multiple files with the find command
body: <p>I am trying to tar multiple files using the find command. I want to find all the files in the directory that contain a specific string in the file name and then tar those files. The string that I am want to find in the file name is the date. </p>
  
  <p>For instance, I have a file name named ulog.20120914.log</p>
  
  <p>What I'm doing right now is:</p>
  
  <pre><code>DAYTWOPREV=`date +%Y%m%d --date='2 days ago'`
  
  function archive {
      cd $1;
      if [ ! -d archive ]; then
          mkdir archive;
      fi
  
  TMPFILE=`mktemp`;
      find . -maxdepth 1 -name "${DAYTWOPREV}*" -type f -print0  &gt; $TMPFILE;
  
  
      TARFILE=archive/${DAYTWOPREV}$2.tar;
      if [ ! -e $TARFILE ]; then
          echo tar cfT $TARFILE /dev/null;
          tar cfT $TARFILE /dev/null;
      fi  
  
  cat $TMPFILE | xargs -0r tar rf $TARFILE
      cat $TMPFILE | xargs -0r rm -rf
      rm -f $TMPFILE;
  
  }
  </code></pre>