title: Check file exist before tar
body: <p>I want to tar files based on the date in filename , but if the file didnt exists, tar create a empty tar files </p>
  
  <p>I have files with anychar_20180322_anychar</p>
  
  <pre><code>anychar_20180322_anychar.txt
  anychar_20180322_anychar.txt
  anychar_20180322_anychar.txt
  anychar_20180322_anychar.txt
  </code></pre>
  
  <p>I want to tar those files , but before that i want to check files exist in the directory.</p>
  
  <p>example-In the below example there is no file for 20180319 . but you can see a tar file in it .</p>
  
  <pre><code>tar: /tmp/dir/*20180319*: Cannot stat: No such file or directory
  tar: Exiting with failure status due to previous erro
  </code></pre>
  
  <p>rs</p>
  
  <pre><code>   -rw------- 1 user group 16M Apr  3 05:31 20180322.tar.gz
    -rw------- 1 user group  45 Apr  3 05:31 20180319.tar.gz
  </code></pre>
  
  <p>code below :</p>
  
  <pre><code>d=$(date -d"10 days ago" +%s)
      dt="$(date -d@$((d - i * 86400)) +%Y%m%d)"
      if [ "$dt" -lt "$d" ] &amp;&amp; [ test -f "*$dt*" ]; then
      tar czf $fn *$dt*
      fi 
      done
  </code></pre>
  
  <p>how to check atleast one file exist in the particular date and proceed to tar else proceed to another date.</p>