Excluding files and folders with tar

Excluding files/folders using tar is very straight forward.

Assuming we have a directory tree similar to this in Linux

-/home/cliper/
            |--- folder/
                     |--- file1
                     |--- file2
                     |--- folder

and we want to exclude file2 and folder to the archive, then command would be like:

tar –czpf filename.tgz --exclude=/home/cliper/folder/file2 --exclude=/home/cliper/folder/folder

Leave a Reply

Close Menu