Tuesday, 26 October 2010

tar with excluding files

Sometimes you may want to create a tar ball of a software project, but you don't want to include everything to the archive you are creating. On Google anwers I found the answer. With a caveat: there is a difference between tar-version you are using (GNU or not GNU). The example given below is for GNU tar.

As I am using bazaar for version management, the directory to be archived usually contains a sub-directory called .bzr. This is obviously a directory to be excluded.

In my Makefile I first define a variable for my project's directory:

This is done for portability.

Then the actual rule to make the tar:

tar: veryclean
(cd ../; tar -cvzf $(PROJECT)-`date +'%b-%d-%y' | tr A-Z a-z`.tgz \
--exclude "$(sourcedir)/.bzr" $(sourcedir))

veryclean is a rule to remove files generated during compilation (like log files), and is called first.

No comments:

Post a Comment