18
3
Can I use the tar command to change directories and use a wildcard file pattern?
Here is what I am trying to do:
tar -cf example.tar -C /path/to/file *.xml
It works if I don't change directory (-C), but I'm trying avoid absolute paths in the tar file.
tar -cf example.tar /path/to/file/*.xml
Here are some of the other attempts I've made:
tar -cf example.tar -C /path/to/file *.xml
tar -cf example.tar -C /path/to/file/ *.xml
tar -cf example.tar -C /path/to/file/ ./*.xml
tar -cf example.tar -C /path/to/file "*.xml"
And this is the error I get:
tar: *.xml: Cannot stat: No such file or directory
I know there are other ways ways to make this work (using find, xargs, etc.) but I was hoping to do this with just the tar command.
Any ideas?