3

I am attempting to transform the paths of a tar file coming from standard input without having to extract the tar first.

This is an apparent duplicate of this question, I am looking for a solution that can be accomplished without having to extract in order to simplify my script, so I do not care if the performance is the same as extracting.

Use Case:

I am creating a tar from git archive, and piping the result to an ssh process that will run on another machine that does not have the --transform option for tar. I will therefore need to transform before sending it over to ssh. I could always extract to a temporary directory, and then recreate another tar with the transform, but I am looking for a one-line solution to temporarily pop into an existing script.

  • If you open a tar file in a text editor you will see that the paths are part of the structure. You will probably need to parse the entire tar structure to accomplish what you want in a safe way (without changing file content that may contain text that looks like a path for example). – grochmal Jul 13 '16 at 18:32
  • 2
    There's an old script named tarcust that can rename files like that in a pipe, maybe you can still find it around. Otherwise, the Perl module Archive::Tar can also do that, but you'll have to write some code. – Satō Katsura Jul 13 '16 at 18:51
  • Workaround that can possibly solve your underlying issue: if that other machine with the more traditional tar happens to have the pax program, pax can handle tar files and transform file names. – Mark Plotnick Jul 13 '16 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.