Thursday, November 12, 2015

[Linux] - tar and exclude certain files or folder

We have below table structure and we want to exclude certain folder(s) before we tar the file. Follow these steps:

  • demo
    • contents
    • videos
    • folder_a
    • folder_b
    • folder_c
    • file_a.php
    • file_b.php

Let say we want to exclude contents and videos folder. So the command would be like this:
tar -czf demo.tar.gz demo/ --exclude='videos' --exclude='contents'