I want to create a tar file excluding certains folders who have many sub-folders and files, but leaving only the main folders that's being excluded. Explaining:


I want my tar to exclude cache and logs content (files and folders) but mantain this empty folders in the tar file.

if I use --exclude=project/cache it excludes the folders from the file. How Can I do this ?

  • 3
    How about --exclude=project/cache/*? – MadHatter Aug 7 '14 at 12:48
  • well I really though I tried that. It worked. Thanks. If you want, put it as an answer so I can accept and you gain credit for it. – Nelson Teixeira Aug 7 '14 at 13:18
  • This will not exclude dot files inside the cache folder, I believe. – cusco Oct 27 '17 at 18:22

You can exclude the files in the directories in question without excluding the directories themselves with --exclude=project/cache/*.

Be mindful that if there are dotfiles in those directories, they will still get picked up in the tar; if that's the case, you may need to work on a more sophisticated regexp.

  • +1 for mentioning about hidden files (dotfiles). – Gaurav Kansal May 31 '19 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.