title: Shell command to tar directory excluding certain files/folders
body: <p>Is there a simple shell command/script that supports excluding certain files/folders from being archived?</p>
  
  <p>I have a directory that need to be archived with a sub directory that has a number of very large files I do not need to backup.</p>
  
  <p><strong>Not quite solutions:</strong></p>
  
  <p>The <code>tar --exclude=PATTERN</code> command matches the given pattern and excludes those files, but I need specific files &amp; folders to be ignored (full file path), otherwise valid files might be excluded.</p>
  
  <p>I could also use the find command to create a list of files and exclude the ones I don't want to archive and pass the list to tar, but that only works with for a small amount of files. I have tens of thousands.</p>
  
  <p>I'm beginning to think the only solution is to create a file with a list of files/folders to be excluded, then use rsync with <code>--exclude-from=file</code> to copy all the files to a tmp directory, and then use tar to archive that directory.</p>
  
  <p>Can anybody think of a better/more efficient solution?</p>
  
  <p>EDIT: <strong>Charles Ma</strong>'s solution works well. The big gotcha is that the <code>--exclude='./folder'</code> <strong>MUST</strong> be at the beginning of the tar command. Full command (cd first, so backup is relative to that directory):</p>
  
  <pre><code>cd /folder_to_backup
  tar --exclude='./folder' --exclude='./upload/folder2' -zcvf /backup/filename.tgz .
  </code></pre>