[英]Use python tarfile add without normpath being applied to arcname
[英]What's the option of tar that corresponds to the `arcname` option in Python `tarfile` module?
在Python中,我们可以为档案中的文件指定替代名称:
with tarfile.open('archive.tar', 'w') as a:
a.add('files', arcname='another_name')
这是通过arcname
参数完成的。
现在,我尝试使用普通的tar
命令执行相同的操作,但是找不到让我指定备用名称的选项。
如果使用GNU tar,则可以使用--transform
选项。
$ rm test.tar
$ touch a_name
$ tar cf test.tar --transform s/.*/another_name/ a_name
$ tar tf test.tar
another_name
根据GNU tar(1)联机帮助页:
--transform, --xform EXPRESSION use sed replace EXPRESSION to transform file names
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.