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