我对以下文件进行了tar'd和zip'd处理:
/opt/abc/xyz/abc.xml
Run Code Online (Sandbox Code Playgroud)
到:
/tmp/backup/abc.xml.tar.gz
Run Code Online (Sandbox Code Playgroud)
我试图解压并解压缩到/opt/abc/xyz/(same path)
目录。
我遇到了以下命令。我以root
用户身份执行它,但没有发现任何错误或输出。我期待下面的命令将提取abc.xml
的 abc.xml.tar.gz
和重命名为abc.xml_v9
。
tar --force-local --transform='s/abc.xml/abc.xml_v9/' -zxpsf /tmp/backup/abc.xml.tar.gz -C /
Run Code Online (Sandbox Code Playgroud)
输出应该是
/opt/abc/xyz/abc.xml_v9
Run Code Online (Sandbox Code Playgroud)
tar 的手册页说以下信息
File name transformations:
--transform=EXPRESSION, --xform=EXPRESSION
use sed replace EXPRESSION to transform file names
File name matching options (affect both exclude and include patterns):
Run Code Online (Sandbox Code Playgroud)
有人可以通过一些示例帮助我理解上述命令吗?
使用您的示例文件 source/tmp/backup/abc.xml.tar.gz
和 destination /opt/abc/xyz/abc.xml_v9
。您可以使用 thsi 命令:
tar --transform='flags=r;s|abc.xml|abc.xml_v9|' -xvf abc.xml.tar.gz -C /opt
Run Code Online (Sandbox Code Playgroud)
或者
tar --transform='flags=r;s/abc.xml/abc.xml_v9/' -xvf abc.xml.tar.gz -C /opt
Run Code Online (Sandbox Code Playgroud)
你会得到
/opt/abc/xyz/abc.xml_v9
Run Code Online (Sandbox Code Playgroud)
看:
https://www.gnu.org/software/tar/manual/html_section/tar_51.html#transform
归档时间: |
|
查看次数: |
13106 次 |
最近记录: |