我可以使用 tar 命令更改目录并使用通配符文件模式吗?
这是我想要做的:
tar -cf example.tar -C /path/to/file *.xml
Run Code Online (Sandbox Code Playgroud)
如果我不更改目录 (-C),它会起作用,但我正在尝试避免 tar 文件中的绝对路径。
tar -cf example.tar /path/to/file/*.xml
Run Code Online (Sandbox Code Playgroud)
以下是我所做的其他一些尝试:
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"
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
tar: *.xml: Cannot stat: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我知道还有其他方法可以使这项工作(使用 find、xargs 等),但我希望仅使用 tar 命令来完成此操作。
有任何想法吗?