Thibauld - Imagination and Execution -

15Feb/103

How to exclude multiple directories while creating an archive with tar

RT @thibauld How to exclude multiple directories while creating an archive with tar

A very quick post again as I've just spent way too much time to find out how to use the --exclude option of tar. All I wanted is tar to omit a few subdirectories while creating an archive of a directory. I was surprised to see how much tar is picky about his --exclude option: if you don't use the exact syntax, it won't work and, unfortunately, the exact syntax is not so easy to figure out from the man page.

So here is the exact syntax you should use if you want to exclude multiples directories with tar:

tar cvfz myproject.tgz --exclude='path/dir_to_exclude1' --exclude='path/dir_to_exclude2' myproject

Hope it will save you some time!

Tagged as: , , 3 Comments