title: create a tar.gz of a directory and clean up the directory except a file?
body: <p>I would like to know if tar (1.15.1, Linux system) already has something like this before creating a script for it.</p>
  
  <p>I would like to create a <code>dir.tar.gz</code> of a given <code>dir/</code> that contains a specific <code>dir/myfile.gz</code>. I would like the command to do 2 specific things:</p>
  
  <ol>
  <li>Preserve <code>dir/myfile.gz</code></li>
  <li>Delete everything else in <code>dir/</code> after the <code>dir.tar.gz</code> is complete.</li>
  </ol>
  
  <p>For example:</p>
  
  <pre><code>tree -if .
  .
  ./dir
  ./dir/dir2
  ./dir/dir2/file3
  ./dir/file1
  ./dir/file2
  ./dir/myfile.gz
  
  2 directories, 4 files
  </code></pre>
  
  <p>I would like the result of the <code>tar</code> command to be:</p>
  
  <pre><code>tree -if  
  .
  ./dir
  ./dir/myfile.gz
  ./dir.tar.gz
  
  1 directory, 2 files
  </code></pre>
  
  <p>I have read about the <code>--delete</code> and <code>--extract</code> options, but I am not sure how to apply them in one single command. Any ideas?</p>