When creating an archive with the command

tar -czvf file.txt.tar.gz /tmp/file.txt

in the archive, the file will also be located along the path /tmp/file.txt .

Is it possible to somehow set your own directory structure inside the archive in the parameters? So that, for example, there was not /tmp/file.txt , but /home/vasya/file.txt ?

  • Answer # 1

    GNU tar has an option --transform (--xform )



    /var /tmp /x $ tar czf a.tgz -P --owner= 0 --group= 0 --xform s ~ tmp ~ home /vasya ~ /tmp/file.txt
    /var /tmp /x $ tar tvf a.tgz -P
    -rw-rw-r--root /root 0 2021-02-10 16:38 /home/vasya/file.txt