What's the option of tar that corresponds to the `arcname` option in Python `tarfile` module?

StackOverflow https://stackoverflow.com/questions/21772758

  •  11-10-2022
  •  | 
  •  

문제

In Python, we can specify an alternative name for a file in the archive:

with tarfile.open('archive.tar', 'w') as a:
    a.add('files', arcname='another_name')

This is done with the arcname parameter.

Now I'm trying to do the same thing with plain tar command, but I can't find the option that let me specify an alternative name.

도움이 되었습니까?

해결책

You can use --transform option if you use GNU tar.

$ rm test.tar
$ touch a_name
$ tar cf test.tar --transform s/.*/another_name/ a_name
$ tar tf test.tar
another_name

According to GNU tar(1) manpage:

 --transform, --xform EXPRESSION
       use sed replace EXPRESSION to transform file names
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top