-1

I'm trying to tar a whole directory except some subdirs..

The dir my-base-dir is zipped but the excluded dirs/files are also included?

tar -cf my-base-dir/bak/site/site.tar my-base-dir --exclude=my-base-dir/bak/db/* --exclude=my-base-dir/bak/site/*

The excluded paths are correct relative to the current working dir.. Because the output tar file is put in one of them

3

You have to put --exclude option before the list of file names to put into (or get out of) the archive i.e.

tar --exclude='my-base-dir/bak/db/*' --exclude='my-base-dir/bak/site/*' -cf my-base-dir/bak/site/site.tar my-base-dir

or you can also use:

tar -cf my-base-dir/bak/site/site.tar --exclude='my-base-dir/bak/db/*' --exclude='my-base-dir/bak/site/*' my-base-dir

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.