Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tar --excludes option to exclude only the directory at current working directory, not subdirectories

Tags:

tar

I want to tar/zip a directory ./ (current working directory) and exclude files in the directory ./vendor, I happened to also have a subdirectory named vendor at ./public/web/vendor, but I want to keep that. I've tried:

tar cfz /private/var/folders/temp/mage6BRQWJ.tar.gz  --exclude=vendor/*     ./
tar cfz /private/var/folders/temp/mage6BRQWJ.tar.gz  --exclude=./vendor/*   ./
tar cfz /private/var/folders/temp/mage6BRQWJ.tar.gz  --exclude="vendor/*"     ./

But these both exclude the subdirectory.

I want to use relative path because I want to exclude all .svn (e.g. example) files from all directories, too.

Is there a way, using relative path , to exclude files in the ./vendor directory but not ./public/web/vendor ?

like image 688
David Lin Avatar asked Sep 03 '25 15:09

David Lin


1 Answers

All you need is the --anchored tag:

GNU tar:

tar cfz mage6BRQWJ.tar.gz --anchored --exclude=vendor *

bsdtar:

bsdtar -czf mage6BRQWJ-1.tar.gz --exclude=^vendor *

That works.

like image 105
David C. Rankin Avatar answered Sep 05 '25 14:09

David C. Rankin