[kwlug-disc] tar --directory help please

Anton Avramov lukav at lukav.com
Wed Jun 4 14:14:38 EDT 2025


OK. Did some searches and RTFM ...

Apparently tar has only exclude patterns and no include :( 

So one solution to your problem would be: 
find /etc/systemd/system -name 'mailman*' -exec realpath --relative-to
/ '{}' \; | tar -czvf ffs.tar --directory=/ --files-from - 

If using some other directory than / you have to change both switches -
-relative-to and --directory

On Wed, 2025-06-04 at 10:59 -0700, Ronald Barnes via kwlug-disc wrote:
> Anton Avramov wrote on 2025-06-04 10:43:
> 
> > to pass the wildcard to tar us single quotes like so:
> > 'etc/systemd/system/mailm*'
> > 
> > Give it a go let us know
> 
> # tar -vvvcf ffs.tar --directory=/ 'etc/systemd/system/mailman*'
> tar: etc/systemd/system/mailman*: Cannot stat: No such file or
> directory
> tar: Exiting with failure status due to previous errors
> 
> 
> Single or double quotes are giving me the same results.
> 
> 
> There's gotta be a way to do this without using `cd /` first!
> 
> 
> I've even tried "escaping" the wildcard:
> 
> # tar -vvvcf ffs.tar --directory=/ 'etc/systemd/system/mailman\*'
> tar: etc/systemd/system/mailman\\*: Cannot stat: No such file or
> directory
> tar: Exiting with failure status due to previous errors
> 
> 
> 
> (Thanks for the suggestion Anton!)
> 
> 
> _______________________________________________
> kwlug-disc mailing list
> To unsubscribe, send an email to kwlug-disc-leave at kwlug.org
> with the subject "unsubscribe", or email
> kwlug-disc-owner at kwlug.org to contact a human being.



More information about the kwlug-disc mailing list