I want to tar a directory that looks like this:
dir
└── workspace
└── node_modules
└── subfolder
└── workspace
└── node_modules
└── other_folder
I want to exclude all folders named node_modules
and exclude the top level folder called workspace
, but no sub folders called workspace
.
So what I want to end up with is this:
dir
└── subfolder
└── workspace
└── other_folder
I'm running this command: tar -czf ./output.tar.gz --exclude=node_modules --exclude=./workspace dir/.
But it's removing all folders called workspace and node_modules, so I instead end up with this:
dir
└── subfolder
└── other_folder
How do I remove only the specific workspace folder that I want, and not all folders with the same name?
For the required case, possible to use tar excludes:
--exclude dir/./folder
-- apply to folder directly under dir--exclude folder
-- will exclude folder anywhere in the treeShould be possible to use:
tar -czf ./output.tar.gz --exclude=node_modules --exclude=dir/./workspace dir/.
Of course possible to use --files-from
, and to generate the list using another tool. This is usually preferred when the list could be large number of files, vs using xargs
.
find dir/. -type f ... | tar cvz ./output.tar.gz -T-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With